Ejemplo n.º 1
0
 /// <summary>
 ///   Returns the angle between the specified vectors in radians.
 /// </summary>
 /// <remarks>
 ///   See http://www.euclideanspace.com/maths/algebra/vectors/angleBetween/index.htm for details.
 /// </remarks>
 /// <param name="v">First vector.</param>
 /// <param name="w">Second vector.</param>
 /// <returns>Angle between the specified vectors in radians.</returns>
 public static float Between(Vector2F v, Vector2F w)
 {
     return(Atan2(w.Y, w.X) - Atan2(v.Y, v.X));
 }
Ejemplo n.º 2
0
        /// <summary>
        ///   Returns the angle between the specified vector and the x-axis.
        ///   Example: FromVector(0.5, 0.5) will return DegreesToRadians(45).
        /// </summary>
        /// <remarks>
        ///   See http://stackoverflow.com/questions/6247153/angle-from-2d-unit-vector for details.
        /// </remarks>
        /// <param name="v">Vector to get the angle of.</param>
        /// <returns>Angle between the specified vector and the x-axis.</returns>
        public static float FromVector(Vector2F v)
        {
            var normalized = v.Normalize();

            return(Atan2(normalized.Y, normalized.X));
        }