-
Notifications
You must be signed in to change notification settings - Fork 1
/
Point3.cs
210 lines (193 loc) · 5.58 KB
/
Point3.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GL3DLab
{
/// <summary>
/// Eine Punktklasse.
/// </summary>
public class Point3
{
/// <summary>
/// Die X-Komponente
/// </summary>
public float x = 0;
/// <summary>
/// Die Y-Komponente
/// </summary>
public float y = 0;
/// <summary>
/// Die Z-Komponente
/// </summary>
public float z = 0;
/// <summary>
/// Assigns Values of p1 to this by leaving adresses as they are
/// </summary>
/// <param name="p1">Point3 to assign values to this</param>
public void assign(Point3 p1)
{
this.x = 0;
this.y = 0;
this.z = 0;
this.x += p1.x;
this.y += p1.y;
this.z += p1.z;
}
/// <summary>
/// sum up the values of p1 and p1
/// </summary>
public static Point3 operator +(Point3 p1, Point3 p2)
{
Point3 p3 = new Point3(0, 0, 0);
p3.x = p1.x + p2.x;
p3.y = p1.y + p2.y;
p3.z = p1.z + p2.z;
return p3;
}
/// <summary>
/// subtracts values of p1 and p2
/// </summary>
public static Point3 operator -(Point3 p1, Point3 p2)
{
Point3 p3 = new Point3(0,0,0);
p3.x = p1.x - p2.x;
p3.y = p1.y - p2.y;
p3.z = p1.z - p2.z;
return p3;
}
/// <summary>
/// multiplies values of p1 with v
/// </summary>
public static Point3 operator *(Point3 p1, double v)
{
Point3 p3 = new Point3(0, 0, 0);
p3.x = p1.x * (float)v;
p3.y = p1.y * (float)v;
p3.z = p1.z * (float)v;
return p3;
}
/// <summary>
/// divides values of p1 with v
/// </summary>
/// <param name="p1"></param>
/// <param name="v"></param>
/// <returns></returns>
public static Point3 operator /(Point3 p1, double v)
{
Point3 p3 = new Point3();
p3.x = p1.x / (float)v;
p3.y = p1.y / (float)v;
p3.z = p1.z / (float)v;
return p3;
}
/// <summary>
/// Entfernung zwischen 2 Punkten.
/// </summary>
/// <param name="p1">Punkt1</param>
/// <param name="p2">Punkt2</param>
/// <returns>Entfernung als Float</returns>
public static float Distance(Point3 p1, Point3 p2)
{
return (float)Math.Sqrt( Math.Pow(p1.x - p2.x, 2) + Math.Pow(p1.y - p2.y, 2) + Math.Pow(p1.z - p2.z, 2));
}
/// <summary>
/// Betrag des Vektors: { Ursprung, Self }
/// </summary>
/// <returns>Betrag</returns>
public float Abs
{
get { return (float)Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2) + Math.Pow(z, 2)); }
}
/// <summary>
/// Constructor
/// </summary>
public Point3(float X, float Y, float Z)
{
x = X;
y = Y;
z = Z;
}
/// <summary>
/// Ein 0-Argument Constructor für die Vererbung
/// </summary>
public Point3()
{
x = 0f;
y = 0f;
z = 0f;
}
/// <summary>
/// Normalizes this Point3. Its length will be 1.
/// </summary>
public void Normalize()
{
float v = (float)(Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2) + Math.Pow(z, 2)));
x /= v;
y /= v;
z /= v;
}
/// <summary>
/// gives Values of Point3 as String
/// </summary>
/// <returns>Values of Point3 as string</returns>
public override string ToString()
{
return x + "|" + y + "|" + z;
}
}
/// <summary>
/// the Vector between Point3 pkt1 and Point3 pkt2
/// </summary>
public class Vector3
{
/// <summary>
/// Der Startpunkt des Vectors
/// </summary>
public Point3 a = new Point3(0, 0, 0);
/// <summary>
/// Der Endpunkt des Vectors
/// </summary>
public Point3 b = new Point3(0, 0, 0);
/// <summary>
/// Constructor
/// </summary>
public Vector3(Point3 pkt1, Point3 pkt2)
{
a = pkt1;
b = pkt2;
}
}
/// <summary>
/// a Square of Point3
/// </summary>
public class Square
{
/// <summary>
/// Ecke des vierecks
/// </summary>
public Point3 a = new Point3(0, 0, 0);
/// <summary>
/// Ecke des vierecks
/// </summary>
public Point3 b = new Point3(0, 0, 0);
/// <summary>
/// Ecke des vierecks
/// </summary>
public Point3 c = new Point3(0, 0, 0);
/// <summary>
/// Ecke des vierecks
/// </summary>
public Point3 d = new Point3(0, 0, 0);
/// <summary>
/// Constructor
/// </summary>
public Square(Point3 pkt1, Point3 pkt2, Point3 pkt3, Point3 pkt4)
{
a = pkt1;
b = pkt2;
c = pkt3;
d = pkt4;
}
}
}