public static double SumComponents(Vector v1) { return (v1.X + v1.Y); }
public static Vector SqrComponents(Vector v1) { return ( new Vector ( v1.X * v1.X, v1.Y * v1.Y ) ); }
public static Vector SqrtComponents(Vector v1) { return ( new Vector ( Math.Sqrt(v1.X), Math.Sqrt(v1.Y) ) ); }
public Vector Max(Vector other) { return Max(this, other); }
public static double Angle(Vector v1, Vector v2) { Vector a = Normalize(v1); Vector b = Normalize(v2); double angle = (Math.Atan2(a.Y, a.X) - Math.Atan2(b.Y, b.X)); if (angle < 0) { angle += Math.PI * 2; } return ( Math.Acos ( Normalize(v1).DotProduct(Normalize(v2)) ) ); }
public double CrossProduct(Vector other) { return CrossProduct(this, other); }
public Vector Interpolate(Vector other, double control) { return Interpolate(this, other, control); }
public static bool IsPerpendicular(Vector v1, Vector v2) { return v1.DotProduct(v2) == 0; }
public static bool IsUnitVector(Vector v1) { return v1.Length == 1; }
public static double DotProduct(Vector v1, Vector v2) { return v1.X * v2.X + v1.Y + v2.Y; }
public static Vector Interpolate(Vector v1, Vector v2, double control) { if (control > 1 || control < 0) { // Error message includes information about the actual value of the // argument throw new ArgumentOutOfRangeException ( "Control Point must be between 0 and 1" ); } else { return ( new Vector ( v1.X * (1 - control) + v2.X * control, v1.Y * (1 - control) + v2.Y * control ) ); } }
public static double CrossProduct(Vector v1, Vector v2) { return v1.X * v2.Y - v1.Y * v2.X; }
public static double AnglePI(Vector v1, Vector v2) { double angle = Angle2PI(v1, v2); if (angle > Math.PI) { angle = (2 * Math.PI) - angle; } return angle; }
public static double Angle2PI(Vector v1, Vector v2) { Vector a = Normalize(v1); Vector b = Normalize(v2); double angle = (Math.Atan2(a.Y, a.X) - Math.Atan2(b.Y, b.X)); if (angle < 0) { angle += Math.PI * 2; } return angle; }
public static double SumComponentSqrs(Vector v1) { Vector v2 = SqrComponents(v1); return v2.SumComponents(); }
public static Vector Max(Vector v1, Vector v2) { if (v1 >= v2) { return v1; } return v2; }
public double Angle(Vector other) { return Angle(this, other); }
public static Vector Min(Vector v1, Vector v2) { if (v1 <= v2) { return v1; } return v2; }
public double DotProduct(Vector other) { return DotProduct(this, other); }
public static Vector Normalize(Vector v1) { // Check for divide by zero errors if (v1.Length == 0) { throw new DivideByZeroException("Magnitude for the Vector is currently 0"); } else { // find the inverse of the vectors magnitude double inverse = 1 / v1.Length; return ( new Vector ( // multiply each component by the inverse of the magnitude v1.X * inverse, v1.Y * inverse ) ); } }
public bool IsPerpendicular(Vector other) { return IsPerpendicular(this, other); }
public static Vector PowComponents(Vector v1, double power) { return ( new Vector ( Math.Pow(v1.X, power), Math.Pow(v1.Y, power) ) ); }
public Vector Min(Vector other) { return Min(this, other); }
public static Double Abs(Vector v1) { return v1.Length; }