Beispiel #1
0
        /// <summary>
        /// Calculates the angle between two vectors in radians.
        /// </summary>
        /// <param name="v1">First vector.</param>
        /// <param name="v2">Second vector.</param>
        /// <returns>Angle of the vectors in degrees.</returns>
        public static double AngleBetween(Vect3D v1, Vect3D v2)
        {
            double angle = Math.Round(v1 * v2 / (v1.GetLength() * v2.GetLength()), 10);

            angle = Math.Acos(angle);
            return(Math.Round(angle, 3));
        }
Beispiel #2
0
        /// <summary>
        /// Rotates a vector clockwise around a specified axis by the given angle.
        /// </summary>
        /// <param name="axis">Rotation axis.</param>
        /// <param name="angle">Rotation angle in radians.</param>
        /// <param name="copy">Creates a copy of the vector. False by default.</param>
        /// <returns></returns>
        public Vect3D RotateVector(Vect3D axis, double angle, bool copy = false)
        {
            axis *= (1 / axis.GetLength());
            Matrix rotationMatrix = Matrix.CreateRotationMatrix(axis, angle);
            Vect3D rotated        = rotationMatrix * this;

            if (!copy)
            {
                this = rotated;
            }
            return(rotated);
        }