-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVector3D.cs
191 lines (167 loc) · 5.59 KB
/
Vector3D.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Doob_eternal_2001
{
struct Vector3D : IComparable<Vector3D>
{
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
public Vector XY
{
get { return (X, Y); }
set { X = value.X; Y = value.Y; }
}
public Vector XZ
{
get { return (X, Z); }
set { X = value.X; Z = value.Y; }
}
public Vector YZ
{
get { return (Y, Z); }
set { Y = value.X; Z = value.Y; }
}
public double Magnitude
{
get { return Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2)); }
private set { }
}
public Vector Angle
{
get { return VectorToRadians(this); }
set { }
}
public override string ToString()
{
return "(" + X + "," + Y + "," + Z + ")";
}
/// <summary>
/// (X, Y)
/// </summary>
/// <param name="coordinate"></param>
public Vector3D(double x, double y, double z)
{
X = x;
Y = y;
Z = z;
}
public Vector3D(Vector xy, double z)
{
X = xy.X;
Y = xy.Y;
Z = z;
}
/// <summary>
/// creates a vector of (size, size, size)
/// </summary>
/// <param name="size"></param>
public Vector3D(double size)
{
X = size;
Y = size;
Z = size;
}
public int CompareTo(Vector3D other)
{
// The magnitude comparison depends on the comparison of
// the underlying Double values.
return Magnitude.CompareTo(other.Magnitude);
}
public static bool operator >(Vector3D operand1, Vector3D operand2)
{
return operand1.CompareTo(operand2) == 1;
}
// Define the is less than operator.
public static bool operator <(Vector3D operand1, Vector3D operand2)
{
return operand1.CompareTo(operand2) == -1;
}
// Define the is greater than or equal to operator.
public static bool operator >=(Vector3D operand1, Vector3D operand2)
{
return operand1.CompareTo(operand2) >= 0;
}
// Define the is less than or equal to operator.
public static bool operator <=(Vector3D operand1, Vector3D operand2)
{
return operand1.CompareTo(operand2) <= 0;
}
public static bool operator ==(Vector3D operand1, Vector3D operand2)
{
return operand1.CompareTo(operand2) == 0;
}
public static bool operator !=(Vector3D operand1, Vector3D operand2)
{
return operand1.CompareTo(operand2) != 0;
}
public static Vector3D operator +(Vector3D a, Vector b)
{
return new Vector3D(a.X + b.X, a.Y + b.Y, a.Z);
}
public static Vector3D operator -(Vector3D a, Vector b)
{
return new Vector3D(a.X - b.X, a.Y - b.Y, a.Z);
}
public static Vector3D operator +(Vector3D a, Vector3D b)
{
return new Vector3D(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
}
public static Vector3D operator -(Vector3D a, Vector3D b)
{
return new Vector3D(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
}
public static Vector3D operator *(Vector3D a, double b)
{
return new Vector3D((int)(a.X * b), (int)(a.Y * b), (int)(a.Z * b));
}
public static Vector3D operator *(Vector3D a, Vector3D b)
{
return new Vector3D(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
}
public static Vector3D operator /(Vector3D a, double b)
{
return new Vector3D((int)Math.Round(a.X / b), (int)Math.Round(a.Y / b), (int)Math.Round(a.Z / b));
}
public static Vector3D operator /(Vector3D a, Vector3D b)
{
return new Vector3D(a.X / b.X, a.Y / b.Y, a.Z / b.Z);
}
public static Vector3D operator %(Vector3D a, Vector3D b)
{
return a - Floor(a / b) * b;
}
public static Vector3D Floor(Vector3D a)
{
return new Vector3D((int)Math.Floor(a.X), (int)Math.Floor(a.Y), (int)Math.Floor(a.Z));
}
/// <summary>
/// converts from a Vector to radians;
/// </summary>
/// <param name="v"></param>
/// <returns></returns>
public static Vector VectorToRadians(Vector3D v)
{
return new Vector(Math.Atan2(v.Y, v.X), Math.Atan2(v.Z, v.XY.Magnitude));
}
public static explicit operator string(Vector3D v)
{
return "(" + v.X + ", " + v.Y + ", " + v.Z + ")";
}
public static implicit operator (double,double,double)(Vector3D v)
{
return (v.X, v.Y, v.Z);
}
public static implicit operator Vector3D((int x, int y, int z) position)
{
return new Vector3D(position.x, position.y, position.z);
}//*/
public static implicit operator Vector3D((IntVector v, int z) position)
{
return new Vector3D(position.v.X, position.v.Y, position.z);
}
}
}