Пример #1
0
        // returns TRUE of vectors are parallel
        public static bool Parallel(Vec3D v1, Vec3D v2)
        {
            float Dot = v1 | v2;

            if (System.Math.Abs(1.0f - Dot) < VECTOR_SMALL_NUMBER)
            {
                return(true);
            }

            return(false);
        }
Пример #2
0
        // normalize this vector so that it is of length 1
        public void Normalize()
        {
            float Magnitude = Size;

            if (Magnitude < VECTOR_SMALL_NUMBER)
            {
                return;
            }

            Vec3D thisc = this / Magnitude;

            this.X = thisc.X;
            this.Y = thisc.Y;
            this.Z = thisc.Z;
        }
Пример #3
0
        /// <summary>this will rotate this vector about the supplied axis according to the angle supplied, and return the rotated result</summary>
        /// <param name="Axis">Axis to rotate about</param>
        public Vec3D RotateAboutAxis(Vec3D Axis, float Angle)
        {
            Vec3D Result = new Vec3D(0f);

            Axis.Normalize();

            float cos = (float)System.Math.Cos(Angle);
            float sin = (float)System.Math.Sin(Angle);

            Result.X += (cos + (1f - cos) * Axis.X * Axis.X) * X;
            Result.X += ((1f - cos) * Result.X * Result.Y - Result.Z * sin) * Axis.Y;
            Result.X += ((1f - cos) * Result.X * Result.Z + Result.Y * sin) * Axis.Z;

            Result.Y += ((1f - cos) * Result.X * Result.Y + Result.Z * sin) * Axis.X;
            Result.Y += (cos + (1f - cos) * Result.Y * Result.Y) * Axis.Y;
            Result.Y += ((1f - cos) * Result.Y * Result.Z - Result.X * sin) * Axis.Z;

            Result.Z += ((1f - cos) * Result.X * Result.Z - Result.Y * sin) * Axis.X;
            Result.Z += ((1f - cos) * Result.Y * Result.Z + Result.X * sin) * Axis.Y;
            Result.Z += (cos + (1f - cos) * Result.Z * Result.Z) * Axis.Z;

            return(Result);
        }
Пример #4
0
 public static float Distance2D(Vec3D v1, Vec3D v2)
 {
     return((v1 - v2).Size2D);
 }
Пример #5
0
        /// <summary>
        /// this will mirror this vector about the supplied normal
        /// </summary>
        /// <param name="Normal">normal to mirror by (e.g. normal of the plane we are reflecting)</param>
        /// <returns></returns>
        public Vec3D Mirror(Vec3D Normal)
        {
            float dot = this | Normal;

            return(this - Normal * (2f * dot));
        }
Пример #6
0
 // returns the angle between two vectors
 public static float AngleBetweenVectors(Vec3D v1, Vec3D v2)
 {
     return((float)System.Math.Acos(v1 | v2));
 }
Пример #7
0
 public bool Parallel(Vec3D vOther)
 {
     return(Parallel(this, vOther));
 }