public static void Main()
Vector2 x = new Vector2(1,2,5);
Vector2 y = new Vector2(10,20,5);
var result = Math.Atan2(x.CrossProduct(y), x.DotProduct(y));
var result2 = Math.Atan2(x.CrossProduct2(y), x.DotProduct2(y));
Console.WriteLine(result);
Console.WriteLine(result2);
public Vector2(float x, float y, float z)
public double DotProduct(Vector2 vector)
return (vector.x * this.x) + (vector.y * this.y) + (vector.z * this.z);
public double CrossProduct(Vector2 vector)
a = this.y * vector.z - this.z * vector.y;
b = this.z * vector.x - this.x * vector.z;
c = this.x * vector.y - this.y * vector.x;
return Math.Sqrt(a*a + b*b + c*c);
public double DotProduct2(Vector2 vector)
return (vector.x * this.x) + (vector.y * this.y);
public double CrossProduct2(Vector2 vector)
return (vector.y * this.y) - (vector.y * this.x);