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