1dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond/*
2dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Licensed to the Apache Software Foundation (ASF) under one or more
3dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * contributor license agreements.  See the NOTICE file distributed with
4dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * this work for additional information regarding copyright ownership.
5dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The ASF licenses this file to You under the Apache License, Version 2.0
6dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * (the "License"); you may not use this file except in compliance with
7dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * the License.  You may obtain a copy of the License at
8dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *
9dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *      http://www.apache.org/licenses/LICENSE-2.0
10dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *
11dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Unless required by applicable law or agreed to in writing, software
12dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * distributed under the License is distributed on an "AS IS" BASIS,
13dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * See the License for the specific language governing permissions and
15dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * limitations under the License.
16dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */
17dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
18dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondpackage org.apache.commons.math.geometry;
19dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
20dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond/**
21dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * This class is a utility representing a rotation order specification
22dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * for Cardan or Euler angles specification.
23dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *
24dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * This class cannot be instanciated by the user. He can only use one
25dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * of the twelve predefined supported orders as an argument to either
26dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * the {@link Rotation#Rotation(RotationOrder,double,double,double)}
27dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * constructor or the {@link Rotation#getAngles} method.
28dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *
29dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @version $Revision: 811827 $ $Date: 2009-09-06 17:32:50 +0200 (dim. 06 sept. 2009) $
30dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @since 1.2
31dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */
32dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondpublic final class RotationOrder {
33dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
34dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Set of Cardan angles.
35dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * this ordered set of rotations is around X, then around Y, then
36dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * around Z
37dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
38dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public static final RotationOrder XYZ =
39dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond      new RotationOrder("XYZ", Vector3D.PLUS_I, Vector3D.PLUS_J, Vector3D.PLUS_K);
40dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
41dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Set of Cardan angles.
42dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * this ordered set of rotations is around X, then around Z, then
43dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * around Y
44dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
45dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public static final RotationOrder XZY =
46dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond      new RotationOrder("XZY", Vector3D.PLUS_I, Vector3D.PLUS_K, Vector3D.PLUS_J);
47dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
48dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Set of Cardan angles.
49dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * this ordered set of rotations is around Y, then around X, then
50dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * around Z
51dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
52dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public static final RotationOrder YXZ =
53dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond      new RotationOrder("YXZ", Vector3D.PLUS_J, Vector3D.PLUS_I, Vector3D.PLUS_K);
54dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
55dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Set of Cardan angles.
56dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * this ordered set of rotations is around Y, then around Z, then
57dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * around X
58dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
59dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public static final RotationOrder YZX =
60dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond      new RotationOrder("YZX", Vector3D.PLUS_J, Vector3D.PLUS_K, Vector3D.PLUS_I);
61dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
62dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Set of Cardan angles.
63dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * this ordered set of rotations is around Z, then around X, then
64dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * around Y
65dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
66dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public static final RotationOrder ZXY =
67dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond      new RotationOrder("ZXY", Vector3D.PLUS_K, Vector3D.PLUS_I, Vector3D.PLUS_J);
68dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
69dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Set of Cardan angles.
70dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * this ordered set of rotations is around Z, then around Y, then
71dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * around X
72dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
73dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public static final RotationOrder ZYX =
74dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond      new RotationOrder("ZYX", Vector3D.PLUS_K, Vector3D.PLUS_J, Vector3D.PLUS_I);
75dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
76dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Set of Euler angles.
77dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * this ordered set of rotations is around X, then around Y, then
78dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * around X
79dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
80dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public static final RotationOrder XYX =
81dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond      new RotationOrder("XYX", Vector3D.PLUS_I, Vector3D.PLUS_J, Vector3D.PLUS_I);
82dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
83dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Set of Euler angles.
84dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * this ordered set of rotations is around X, then around Z, then
85dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * around X
86dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
87dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public static final RotationOrder XZX =
88dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond      new RotationOrder("XZX", Vector3D.PLUS_I, Vector3D.PLUS_K, Vector3D.PLUS_I);
89dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
90dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Set of Euler angles.
91dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * this ordered set of rotations is around Y, then around X, then
92dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * around Y
93dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
94dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public static final RotationOrder YXY =
95dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond      new RotationOrder("YXY", Vector3D.PLUS_J, Vector3D.PLUS_I, Vector3D.PLUS_J);
96dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
97dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Set of Euler angles.
98dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * this ordered set of rotations is around Y, then around Z, then
99dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * around Y
100dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
101dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public static final RotationOrder YZY =
102dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond      new RotationOrder("YZY", Vector3D.PLUS_J, Vector3D.PLUS_K, Vector3D.PLUS_J);
103dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
104dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Set of Euler angles.
105dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * this ordered set of rotations is around Z, then around X, then
106dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * around Z
107dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
108dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public static final RotationOrder ZXZ =
109dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond      new RotationOrder("ZXZ", Vector3D.PLUS_K, Vector3D.PLUS_I, Vector3D.PLUS_K);
110dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
111dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Set of Euler angles.
112dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * this ordered set of rotations is around Z, then around Y, then
113dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * around Z
114dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
115dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public static final RotationOrder ZYZ =
116dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond      new RotationOrder("ZYZ", Vector3D.PLUS_K, Vector3D.PLUS_J, Vector3D.PLUS_K);
117dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
118dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Name of the rotations order. */
119dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private final String name;
120dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
121dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Axis of the first rotation. */
122dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private final Vector3D a1;
123dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
124dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Axis of the second rotation. */
125dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private final Vector3D a2;
126dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
127dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Axis of the third rotation. */
128dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private final Vector3D a3;
129dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
130dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Private constructor.
131dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * This is a utility class that cannot be instantiated by the user,
132dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * so its only constructor is private.
133dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param name name of the rotation order
134dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param a1 axis of the first rotation
135dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param a2 axis of the second rotation
136dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param a3 axis of the third rotation
137dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
138dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    private RotationOrder(final String name,
139dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond                          final Vector3D a1, final Vector3D a2, final Vector3D a3) {
140dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.name = name;
141dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.a1   = a1;
142dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.a2   = a2;
143dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        this.a3   = a3;
144dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
145dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
146dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Get a string representation of the instance.
147dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return a string representation of the instance (in fact, its name)
148dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
149dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    @Override
150dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public String toString() {
151dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return name;
152dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
153dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
154dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Get the axis of the first rotation.
155dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return axis of the first rotation
156dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
157dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public Vector3D getA1() {
158dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return a1;
159dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
160dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
161dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Get the axis of the second rotation.
162dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return axis of the second rotation
163dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
164dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public Vector3D getA2() {
165dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return a2;
166dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
167dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
168dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /** Get the axis of the second rotation.
169dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return axis of the second rotation
170dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
171dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    public Vector3D getA3() {
172dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond        return a3;
173dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    }
174dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
175dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond}
176