1 package org.opentrafficsim.core.math;
2
3 import java.io.Serializable;
4 import java.util.Locale;
5
6 import org.djunits.unit.AngleUnit;
7 import org.djunits.value.ValueRuntimeException;
8 import org.djunits.value.storage.StorageType;
9 import org.djunits.value.vdouble.scalar.Angle;
10 import org.djunits.value.vdouble.vector.AngleVector;
11 import org.djunits.value.vdouble.vector.base.DoubleVector;
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public class Angle3D implements Serializable
27 {
28
29 private static final long serialVersionUID = 20160000L;
30
31
32 private final AngleVector rotation;
33
34
35
36
37
38 public Angle3D(final AngleVector rotation) throws ValueRuntimeException
39 {
40 if (rotation.size() != 3)
41 {
42 throw new ValueRuntimeException("Size of an RPY-rotation vector should be exactly 3. Got: " + rotation);
43 }
44 this.rotation = rotation;
45 }
46
47
48
49
50
51
52
53 public Angle3D(final Angle roll, final Angle pitch, final Angle yaw) throws ValueRuntimeException
54 {
55 this.rotation = DoubleVector.instantiate(new Angle[] {roll, pitch, yaw}, AngleUnit.SI, StorageType.DENSE);
56 }
57
58
59
60
61
62
63
64
65 public Angle3D(final double roll, final double pitch, final double yaw, final AngleUnit unit) throws ValueRuntimeException
66 {
67 this.rotation = DoubleVector.instantiate(new double[] {roll, pitch, yaw}, unit, StorageType.DENSE);
68 }
69
70
71
72
73 public final Angle getRoll()
74 {
75 try
76 {
77 return this.rotation.get(0);
78 }
79 catch (ValueRuntimeException exception)
80 {
81
82 throw new RuntimeException(
83 "getRoll() gave an exception; apparently vector " + this.rotation + " was not constructed right",
84 exception);
85 }
86 }
87
88
89
90
91 public final Angle getPitch()
92 {
93 try
94 {
95 return this.rotation.get(1);
96 }
97 catch (ValueRuntimeException exception)
98 {
99
100 throw new RuntimeException(
101 "getPitch() gave an exception; apparently vector " + this.rotation + " was not constructed right",
102 exception);
103 }
104 }
105
106
107
108
109 public final Angle getYaw()
110 {
111 try
112 {
113 return this.rotation.get(2);
114 }
115 catch (ValueRuntimeException exception)
116 {
117
118 throw new RuntimeException(
119 "getYaw() gave an exception; apparently vector " + this.rotation + " was not constructed right", exception);
120 }
121 }
122
123
124 @Override
125 public final String toString()
126 {
127 return String.format(Locale.US, "Angle3D.Rel roll %s, pitch %s, yaw %s", getRoll(), getPitch(), getYaw());
128 }
129 }