-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.java
More file actions
209 lines (178 loc) · 4.08 KB
/
Point.java
File metadata and controls
209 lines (178 loc) · 4.08 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
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
class Point {
protected double x;
protected double y;
protected double z;
Point() {
x = 0;
y = 0;
z = 0;
}
Point(int fx, int fy, int fz) {
x = (float) fx;
y = (float) fy;
z = (float) fz;
}
Point(double fx, double fy, double fz) {
x = fx;
y = fy;
z = fz;
}
Point(Point other) {
this.x = other.GetExX();
this.y = other.GetExY();
this.z = other.GetExZ();
}
public void Print_Info() {
System.out.println("Point:\n=============================");
System.out.println(x + " " + y + " " + z);
}
int GetX() {
return (int) Math.round(x);
}
int GetY() {
return (int) Math.round(y);
}
int GetZ() {
return (int) Math.round(z);
}
double GetExX() {
return x;
}
double GetExY() {
return y;
}
double GetExZ() {
return z;
}
void SetX(double newx) {
x = newx;
}
void SetY(double newy) {
y = newy;
}
void SetZ(double newz) {
z = newz;
}
public String toString() {
String locationX = String.format("%.3f", x);
String locationY = String.format("%.3f", y);
String locationZ = String.format("%.3f", z);
return "X: " + locationX + " Y: " + locationY + " Z: " + locationZ;
}
public void RotateClockwiseAboutYAxis(Point p, float degrees) {
if (degrees == 0.0)
return;
double changex = -p.GetExX();
double changez = -p.GetExZ();
double s = Util.sin(degrees);
double c = Util.cos(degrees);
x += changex;
z += changez;
double hx = z * s;
hx = hx + (x * c);
double hz = z * c;
z = hz - (x * s);
x = hx;
x -= changex;
z -= changez;
}
public void RotateCounterClockwiseAboutYAxis(Point p, float degrees) {
/*
* if(degrees == 0.0) return; Point exp = new Point(p); double dist =
* Util.Distance_Between(exp, new Point(0, 0, 0)); Util.NormalizeVector(exp);
* Util.MovePointAlongVector(this, new Point(-exp.GetExX(), -exp.GetExY(),
* -exp.GetExZ()), dist); double[] values = { Util.cos(degrees), 0,
* -Util.sin(degrees), 0, 1, 0, Util.sin(degrees), 0, Util.cos(degrees) };
* Matrix m = new Matrix(values); m.Multiply(this);
* Util.MovePointAlongVector(this, exp, dist);
*/
if (degrees == 0.0)
return;
double changex = -p.GetExX();
double changez = -p.GetExZ();
double s = Util.sin(-degrees);
double c = Util.cos(-degrees);
x += changex;
z += changez;
double hx = z * s;
hx = hx + (x * c);
double hz = z * c;
z = hz - (x * s);
x = hx;
x -= changex;
z -= changez;
}
public void RotateClockwiseAboutXAxis(Point p, float degrees) {
if (degrees == 0.0)
return;
double changey = -p.GetExY();
double changez = -p.GetExZ();
double s = Util.sin(degrees);
double c = Util.cos(degrees);
y += changey;
z += changez;
double hy = y * c;
hy = hy - (z * s);
double hz = y * s;
z = hz + (z * c);
y = hy;
y -= changey;
z -= changez;
}
public void RotateCounterClockwiseAboutXAxis(Point p, float degrees) {
if (degrees == 0.0)
return;
double changey = -p.GetExY();
double changez = -p.GetExZ();
double s = Util.sin(-degrees);
double c = Util.cos(-degrees);
y += changey;
z += changez;
double hy = y * c;
hy = hy - (z * s);
double hz = y * s;
z = hz + (z * c);
y = hy;
y -= changey;
z -= changez;
}
void RotateClockwiseAboutZAxis(Point p, float degrees) {
if (degrees == 0.0)
return;
double changex = -p.GetExX();
double changey = -p.GetExY();
double s = Util.sin(-degrees);
double c = Util.cos(-degrees);
x += changex;
y += changey;
double hx = x * c;
hx = hx - (y * s);
double hy = x * s;
y = hy + (y * c);
x = hx;
x -= changex;
y -= changey;
}
public void RotateCounterClockwiseAboutZAxis(Point p, float degrees) {
if (degrees == 0.0)
return;
double changex = -p.GetExX();
double changey = -p.GetExY();
double s = Util.sin(degrees);
double c = Util.cos(degrees);
x += changex;
y += changey;
double hx = x * c;
hx = hx - (y * s);
double hy = x * s;
y = hy + (y * c);
x = hx;
x -= changex;
y -= changey;
}
public boolean SameLocation(Point p1, Point p2) {
if ((p1.GetX() == p2.GetX()) && (p1.GetY() == p2.GetY()) && (p1.GetZ() == p2.GetZ()))
return true;
return false;
}
}