-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector2D.cs
More file actions
92 lines (76 loc) · 2 KB
/
Vector2D.cs
File metadata and controls
92 lines (76 loc) · 2 KB
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
88
89
90
91
92
using System;
using System.Drawing;
namespace SharedTools
{
public struct Vector2D
{
public float X { get; set; }
public float Y { get; set; }
public static readonly Vector2D Null = new Vector2D(0, 0);
public Vector2D(float x, float y)
{
X = x;
Y = y;
}
public static Vector2D operator +(Vector2D a, Vector2D b)
{
a.X += b.X;
a.Y += b.Y;
return a;
}
public static Vector2D operator -(Vector2D a, Vector2D b)
{
a.X -= b.X;
a.Y -= b.Y;
return a;
}
public static float operator *(Vector2D a, Vector2D b)
{
return a.X * b.X + a.Y * b.Y;
}
public static Vector2D operator *(float a, Vector2D b)
{
b.X *= a;
b.Y *= a;
return b;
}
public static Vector2D operator /(Vector2D a, float b)
{
a.X /= b;
a.Y /= b;
return a;
}
public float Betrag2()
{
return X * X + Y * Y;
}
public float Betrag()
{
return (float)Math.Sqrt(Betrag2());
}
public static bool IstKollinear(Vector2D a, Vector2D b)
{
return b.X / a.X == b.Y / a.Y;
}
public static float Schnittwinkel(Vector2D a, Vector2D b)
{
return (float)(Math.Acos(Math.Abs(a * b) / (a.Betrag() * b.Betrag())) / Math.PI * 180D);
}
public override string ToString()
{
return X + ", " + Y;
}
public static implicit operator Vector2D(PointF p)
{
return new Vector2D(p.X, p.Y);
}
public static implicit operator PointF(Vector2D v)
{
return new PointF(v.X, v.Y);
}
public static implicit operator Vector(Vector2D v)
{
return new Vector(v.X, v.Y);
}
}
}