-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVec2.cs
57 lines (43 loc) · 1.3 KB
/
Vec2.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
namespace AutoPolarAlign
{
public struct Vec2
{
public double X;
public double Y;
public double Azimuth
{
get => X;
set => X = value;
}
public double Altitude
{
get => Y;
set => Y = value;
}
public double Length => (double)Math.Sqrt(X * X + Y * Y);
public Vec2(double x, double y)
{
X = x;
Y = y;
}
public double Dot(Vec2 other)
{
return X * other.X + Y * other.Y;
}
public Vec2 Normalized()
{
return this / Length;
}
public static Vec2 operator +(Vec2 p) => p;
public static Vec2 operator -(Vec2 p) => new Vec2(-p.X, -p.Y);
public static Vec2 operator +(Vec2 p1, Vec2 p2) => new Vec2(p1.X + p2.X, p1.Y + p2.Y);
public static Vec2 operator -(Vec2 p1, Vec2 p2) => new Vec2(p1.X - p2.X, p1.Y - p2.Y);
public static Vec2 operator *(Vec2 p, double scalar) => new Vec2(p.X * scalar, p.Y * scalar);
public static Vec2 operator /(Vec2 p, double scalar) => new Vec2(p.X / scalar, p.Y / scalar);
public override string ToString()
{
return "(" + X + ", " + Y + ")";
}
}
}