Exemplo n.º 1
0
 //Create a new vector with x and y parameters
 public static Vector createVector(float x, float y)
 {
     Vector v = new Vector();
     v.X = x;
     v.Y = y;
     return v;
 }
Exemplo n.º 2
0
 public static Vector Normalize(Vector v)
 {
     float l = Length(v);
     v.X = v.X / l;
     v.Y = v.Y / l;
     return v;
 }
Exemplo n.º 3
0
 //Distance between two vectors
 public static float Distance(Vector v1 , Vector v2)
 {
     return (float)Math.Sqrt(Math.Pow(v2.X - v1.X, 2) + Math.Pow(v2.Y - v1.Y, 2));
 }
Exemplo n.º 4
0
 //Returns length of a vector
 public static float Length(Vector v)
 {
     return (float)Math.Sqrt((v.X * v.X) + (v.Y * v.Y));
 }
Exemplo n.º 5
0
 //Angle between two vectors returns degrees
 public static double Angle(Vector v1, Vector v2)
 {
     float dot = v1 * v2;
     float cross = (v1.X * v2.Y) - (v1.Y * v2.X);
     return Math.Atan2(cross, dot) * 180 / Math.PI;
 }