예제 #1
0
파일: Vector.cs 프로젝트: Zyrst/CHash-Kurs
 //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;
 }
예제 #2
0
 public static Vector Normalize(Vector v)
 {
     float l = Length(v);
     v.X = v.X / l;
     v.Y = v.Y / l;
     return v;
 }
예제 #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));
 }
예제 #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));
 }
예제 #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;
 }