Esempio n. 1
0
 /// <summary>
 /// Angle in degrees between two directions. The angle is positive if the direction passed as second parameter points at the left of the first one
 /// (considering the first one as a vector pointing forward). The angle is negative otherwise.
 /// </summary>
 /// <param name="dir1"></param>
 /// <param name="dir2"></param>
 /// <returns> Returns an angles between two directions.  </returns>
 static public double AngleBetweenDirections(Vector2D dir1, Vector2D dir2)
 {
     Vector2D dir1norm = dir1.Normalized();
     Vector2D dir2norm = dir2.Normalized();
     double dot = dir1norm.Dot(dir2norm);
     double angle = Math.Acos(dot) * 180 / Math.PI;
     
     // If the coss product vector points down, than dir2 poitn to the left relatively to dir1
     if (dir1.Cross(dir2) >  0) 
         angle *= -1;
     return angle;
 }
Esempio n. 2
0
 static public Vector2D Direction(Vector2D fromPoint, Vector2D toPoint) {
     Vector2D result = new Vector2D(0, 0);
     result.X = toPoint.X - fromPoint.X;
     result.Y = toPoint.Y - fromPoint.Y;
     return result.Normalized();
 }