View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.geometry.euclidean.threed.rotation;
18  
19  import org.apache.commons.geometry.euclidean.threed.Vector3D;
20  
21  /** Enum containing rotation axis sequences for use in defining 3 dimensional rotations.
22   */
23  public enum AxisSequence {
24  
25      /** Set of Tait-Bryan angles around the <strong>X</strong>, <strong>Y</strong>, and
26       * <strong>Z</strong> axes in that order.
27       */
28      XYZ(AxisSequenceType.TAIT_BRYAN, Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_Z),
29  
30      /** Set of Tait-Bryan angles around the <strong>X</strong>, <strong>Z</strong>, and
31       * <strong>Y</strong> axes in that order.
32       */
33      XZY(AxisSequenceType.TAIT_BRYAN, Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_Y),
34  
35      /** Set of Tait-Bryan angles around the <strong>Y</strong>, <strong>X</strong>, and
36       * <strong>Z</strong> axes in that order.
37       */
38      YXZ(AxisSequenceType.TAIT_BRYAN, Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Z),
39  
40      /** Set of Tait-Bryan angles around the <strong>Y</strong>, <strong>Z</strong>, and
41       * <strong>X</strong> axes in that order.
42       */
43      YZX(AxisSequenceType.TAIT_BRYAN, Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_X),
44  
45      /** Set of Cardan angles.
46       * this ordered set of rotations is around Z, then around X, then
47       * around Y
48       */
49      ZXY(AxisSequenceType.TAIT_BRYAN, Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Y),
50  
51      /** Set of Tait-Bryan angles around the <strong>Z</strong>, <strong>Y</strong>, and
52       * <strong>X</strong> axes in that order.
53       */
54      ZYX(AxisSequenceType.TAIT_BRYAN, Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_X),
55  
56      /** Set of Euler angles around the <strong>X</strong>, <strong>Y</strong>, and
57       * <strong>X</strong> axes in that order.
58       */
59      XYX(AxisSequenceType.EULER, Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_X),
60  
61      /** Set of Euler angles around the <strong>X</strong>, <strong>Z</strong>, and
62       * <strong>X</strong> axes in that order.
63       */
64      XZX(AxisSequenceType.EULER, Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_X),
65  
66      /** Set of Euler angles around the <strong>Y</strong>, <strong>X</strong>, and
67       * <strong>Y</strong> axes in that order.
68       */
69      YXY(AxisSequenceType.EULER, Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Y),
70  
71      /** Set of Euler angles around the <strong>Y</strong>, <strong>Z</strong>, and
72       * <strong>Y</strong> axes in that order.
73       */
74      YZY(AxisSequenceType.EULER, Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_Y),
75  
76      /** Set of Euler angles around the <strong>Z</strong>, <strong>X</strong>, and
77       * <strong>Z</strong> axes in that order.
78       */
79      ZXZ(AxisSequenceType.EULER, Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Z),
80  
81      /** Set of Euler angles around the <strong>Z</strong>, <strong>Y</strong>, and
82       * <strong>Z</strong> axes in that order.
83       */
84      ZYZ(AxisSequenceType.EULER, Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_Z);
85  
86      /** The type of axis sequence. */
87      private final AxisSequenceType type;
88  
89      /** Axis of the first rotation. */
90      private final Vector3D axis1;
91  
92      /** Axis of the second rotation. */
93      private final Vector3D axis2;
94  
95      /** Axis of the third rotation. */
96      private final Vector3D axis3;
97  
98      /** Simple constructor.
99       * @param type the axis sequence type
100      * @param axis1 first rotation axis
101      * @param axis2 second rotation axis
102      * @param axis3 third rotation axis
103      */
104     AxisSequence(final AxisSequenceType type, final Vector3D axis1, final Vector3D axis2, final Vector3D axis3) {
105         this.type = type;
106 
107         this.axis1 = axis1;
108         this.axis2 = axis2;
109         this.axis3 = axis3;
110     }
111 
112     /** Get the axis sequence type.
113      * @return the axis sequence type
114      */
115     public AxisSequenceType getType() {
116         return type;
117     }
118 
119     /** Get the first rotation axis.
120      * @return the first rotation axis
121      */
122     public Vector3D getAxis1() {
123         return axis1;
124     }
125 
126     /** Get the second rotation axis.
127      * @return the second rotation axis
128      */
129     public Vector3D getAxis2() {
130         return axis2;
131     }
132 
133     /** Get the third rotation axis.
134      * @return the third rotation axis
135      */
136     public Vector3D getAxis3() {
137         return axis3;
138     }
139 
140     /** Get an array containing the 3 rotation axes in order.
141      * @return a 3-element array containing the rotation axes in order
142      */
143     public Vector3D[] toArray() {
144         return new Vector3D[]{axis1, axis2, axis3};
145     }
146 }