// 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); }
// 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; }
/// <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); }
/// <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; }
public bool Parallel(Vec3D vOther) { return Parallel(this, vOther); }
/// <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); }
// 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; }
// returns the angle between two vectors public static float AngleBetweenVectors(Vec3D v1, Vec3D v2) { return (float)System.Math.Acos(v1 | v2); }
public static float Distance2D(Vec3D v1, Vec3D v2) { return((v1 - v2).Size2D); }
/// <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)); }
// returns the angle between two vectors public static float AngleBetweenVectors(Vec3D v1, Vec3D v2) { return((float)System.Math.Acos(v1 | v2)); }
public bool Parallel(Vec3D vOther) { return(Parallel(this, vOther)); }
public static float Distance2D(Vec3D v1, Vec3D v2) { return (v1 - v2).Size2D; }