Vector2D v = new Vector2D(1, 1); double angle = Math.Atan2(v.Y, v.X); Console.WriteLine(angle);
0.7853981633974483
Vector2D v1 = new Vector2D(1, 0); Vector2D v2 = new Vector2D(0, 1); double angle1 = Math.Atan2(v1.Y, v1.X); double angle2 = Math.Atan2(v2.Y, v2.X); Console.WriteLine(angle1); Console.WriteLine(angle2);
0 1.5707963267948966Description: This example creates two Vector2D objects - one with x=1 and y=0, and the other with x=0 and y=1. The Atan2 function is then called on each of these vectors to calculate the angles between the x-axis and each vector. In the first case, the vector is on the x-axis itself, so the angle is 0 degrees. In the second case, the vector is pointing straight up, so the angle is 90 degrees or pi/2 radians. The Vector2D Atan2 function is part of the System.Math library in C#.