-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector.cs
More file actions
33 lines (29 loc) · 730 Bytes
/
Vector.cs
File metadata and controls
33 lines (29 loc) · 730 Bytes
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
namespace Gravity_Simulation
{
public class Vector(double x, double y)
{
public double X { get; set; } = x;
public double Y { get; set; } = y;
public static Vector operator -(Vector v1, Vector v2)
{
return new Vector(v1.X - v2.X, v1.Y - v2.Y);
}
public double LengthSquared()
{
return X * X + Y * Y;
}
public double Length()
{
return Math.Sqrt(LengthSquared());
}
public void Normalize()
{
double length = Math.Sqrt(X * X + Y * Y);
if (length > 0)
{
X /= length;
Y /= length;
}
}
}
}