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