/
Vector2.cs
87 lines (69 loc) · 1.71 KB
/
Vector2.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
namespace MathLibrary
{
public class Vector2
{
public Vector2(float X, float Y)
{
x = X;
y = Y;
}
public Vector2() {}
public float x;
public float y;
public Vector2 Increase(float s)
{
Vector2 scaled = new Vector2
{
x = x * s,
y = y * s
};
return scaled;
}
public Vector2 Reduce(float s)
{
Vector2 scaled = new Vector2
{
x = x / s,
y = y / s
};
return scaled;
}
public Vector2 Normalized()
{
Vector2 normalized = new Vector2
{
x = this.x / Length(),
y = this.y / Length()
};
return normalized;
}
public Vector2 AddVector(ref Vector2 vector)
{
Vector2 vector2 = new Vector2
{
x = x + vector.x,
y = y + vector.y
};
return vector2;
}
public Vector2 SubtractVector(ref Vector2 vector)
{
return new Vector2(x - vector.x, y - vector.y);
}
public float Length()
{
float lenght = (float)Math.Sqrt((x * x) + (y * y));
return (float)Math.Round(lenght, 2);
}
public float LengthSqr()
{
float lenght = (x * x) + (y * y);
return (float)Math.Round(lenght, 2);
}
public float Dotproduct(ref Vector2 a, ref Vector2 b)
{
return (a.x * b.x) + (a.y * b.y);
}
}
}