1 package org.opentrafficsim.core.math;
2
3 import java.util.Locale;
4
5 import org.djunits.unit.AngleUnit;
6 import org.djunits.value.StorageType;
7 import org.djunits.value.ValueException;
8 import org.djunits.value.vdouble.scalar.Angle;
9 import org.djunits.value.vdouble.vector.AngleVector;
10
11
12
13
14
15
16
17
18
19
20
21
22
23 public interface Rotation3D
24 {
25
26
27
28
29
30
31
32
33
34
35
36
37 class Abs
38 {
39
40 private final AngleVector.Abs rotation;
41
42
43
44
45
46 public Abs(final AngleVector.Abs rotation) throws ValueException
47 {
48 super();
49 if (rotation.size() != 3)
50 {
51 throw new ValueException("Size of an RPY-rotation vector should be exactly 3. Got: " + rotation);
52 }
53 this.rotation = rotation;
54 }
55
56
57
58
59
60
61
62 public Abs(final Angle.Abs roll, final Angle.Abs pitch, final Angle.Abs yaw) throws ValueException
63 {
64 super();
65 this.rotation = new AngleVector.Abs(new Angle.Abs[]{roll, pitch, yaw}, StorageType.DENSE);
66 }
67
68
69
70
71
72
73
74
75 public Abs(final double roll, final double pitch, final double yaw, final AngleUnit unit) throws ValueException
76 {
77 super();
78 this.rotation = new AngleVector.Abs(new double[]{roll, pitch, yaw}, unit, StorageType.DENSE);
79 }
80
81
82
83
84 public final Angle.Abs getRoll()
85 {
86 try
87 {
88 return this.rotation.get(0);
89 }
90 catch (ValueException exception)
91 {
92
93 throw new RuntimeException("getRoll() gave an exception; apparently vector " + this.rotation
94 + " was not constructed right", exception);
95 }
96 }
97
98
99
100
101 public final Angle.Abs getPitch()
102 {
103 try
104 {
105 return this.rotation.get(1);
106 }
107 catch (ValueException exception)
108 {
109
110 throw new RuntimeException("getPitch() gave an exception; apparently vector " + this.rotation
111 + " was not constructed right", exception);
112 }
113 }
114
115
116
117
118 public final Angle.Abs getYaw()
119 {
120 try
121 {
122 return this.rotation.get(2);
123 }
124 catch (ValueException exception)
125 {
126
127 throw new RuntimeException("getYaw() gave an exception; apparently vector " + this.rotation
128 + " was not constructed right", exception);
129 }
130 }
131
132
133 public final String toString()
134 {
135 return String
136 .format(Locale.US, "Rotation3D.Abs roll %s, pitch %s, yaw %s", getRoll(), getPitch(), getYaw());
137 }
138
139 }
140
141
142
143
144
145
146
147
148
149
150
151
152
153 class Rel
154 {
155
156 private final AngleVector.Rel rotation;
157
158
159
160
161
162 public Rel(final AngleVector.Rel rotation) throws ValueException
163 {
164 super();
165 if (rotation.size() != 3)
166 {
167 throw new ValueException("Size of an RPY-rotation vector should be exactly 3. Got: " + rotation);
168 }
169 this.rotation = rotation;
170 }
171
172
173
174
175
176
177
178 public Rel(final Angle.Rel roll, final Angle.Rel pitch, final Angle.Rel yaw) throws ValueException
179 {
180 super();
181 this.rotation = new AngleVector.Rel(new Angle.Rel[]{roll, pitch, yaw}, StorageType.DENSE);
182 }
183
184
185
186
187
188
189
190
191 public Rel(final double roll, final double pitch, final double yaw, final AngleUnit unit) throws ValueException
192 {
193 super();
194 this.rotation = new AngleVector.Rel(new double[]{roll, pitch, yaw}, unit, StorageType.DENSE);
195 }
196
197
198
199
200 public final Angle.Rel getRoll()
201 {
202 try
203 {
204 return this.rotation.get(0);
205 }
206 catch (ValueException exception)
207 {
208
209 throw new RuntimeException("getRoll() gave an exception; apparently vector " + this.rotation
210 + " was not constructed right", exception);
211 }
212 }
213
214
215
216
217 public final Angle.Rel getPitch()
218 {
219 try
220 {
221 return this.rotation.get(1);
222 }
223 catch (ValueException exception)
224 {
225
226 throw new RuntimeException("getPitch() gave an exception; apparently vector " + this.rotation
227 + " was not constructed right", exception);
228 }
229 }
230
231
232
233
234 public final Angle.Rel getYaw()
235 {
236 try
237 {
238 return this.rotation.get(2);
239 }
240 catch (ValueException exception)
241 {
242
243 throw new RuntimeException("getYaw() gave an exception; apparently vector " + this.rotation
244 + " was not constructed right", exception);
245 }
246 }
247
248
249 public final String toString()
250 {
251 return String
252 .format(Locale.US, "Rotation3D.Rel roll %s, pitch %s, yaw %s", getRoll(), getPitch(), getYaw());
253 }
254
255 }
256
257 }