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 * https://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 18 /* 19 * This is not the original file distributed by the Apache Software Foundation 20 * It has been modified by the Hipparchus project 21 */ 22 23 package org.hipparchus.geometry.euclidean.threed; 24 25 import java.util.HashMap; 26 import java.util.Map; 27 28 import org.hipparchus.exception.MathIllegalStateException; 29 import org.hipparchus.geometry.LocalizedGeometryFormats; 30 31 32 /** 33 * This class is a utility representing a rotation order specification 34 * for Cardan or Euler angles specification. 35 * 36 * This class cannot be instanciated by the user. He can only use one 37 * of the twelve predefined supported orders as an argument to either 38 * the {@link Rotation#Rotation(RotationOrder, RotationConvention, double, double, double)} 39 * constructor or the {@link Rotation#getAngles} method. 40 * 41 * Since Hipparchus 1.7 this class is an enumerate class. 42 * 43 */ 44 public enum RotationOrder { 45 46 /** Set of Cardan angles. 47 * this ordered set of rotations is around X, then around Y, then 48 * around Z 49 */ 50 XYZ("XYZ", Vector3D.PLUS_I, Vector3D.PLUS_J, Vector3D.PLUS_K), 51 52 /** Set of Cardan angles. 53 * this ordered set of rotations is around X, then around Z, then 54 * around Y 55 */ 56 XZY("XZY", Vector3D.PLUS_I, Vector3D.PLUS_K, Vector3D.PLUS_J), 57 58 /** Set of Cardan angles. 59 * this ordered set of rotations is around Y, then around X, then 60 * around Z 61 */ 62 YXZ("YXZ", Vector3D.PLUS_J, Vector3D.PLUS_I, Vector3D.PLUS_K), 63 64 /** Set of Cardan angles. 65 * this ordered set of rotations is around Y, then around Z, then 66 * around X 67 */ 68 YZX("YZX", Vector3D.PLUS_J, Vector3D.PLUS_K, Vector3D.PLUS_I), 69 70 /** Set of Cardan angles. 71 * this ordered set of rotations is around Z, then around X, then 72 * around Y 73 */ 74 ZXY("ZXY", Vector3D.PLUS_K, Vector3D.PLUS_I, Vector3D.PLUS_J), 75 76 /** Set of Cardan angles. 77 * this ordered set of rotations is around Z, then around Y, then 78 * around X 79 */ 80 ZYX("ZYX", Vector3D.PLUS_K, Vector3D.PLUS_J, Vector3D.PLUS_I), 81 82 /** Set of Euler angles. 83 * this ordered set of rotations is around X, then around Y, then 84 * around X 85 */ 86 XYX("XYX", Vector3D.PLUS_I, Vector3D.PLUS_J, Vector3D.PLUS_I), 87 88 /** Set of Euler angles. 89 * this ordered set of rotations is around X, then around Z, then 90 * around X 91 */ 92 XZX("XZX", Vector3D.PLUS_I, Vector3D.PLUS_K, Vector3D.PLUS_I), 93 94 /** Set of Euler angles. 95 * this ordered set of rotations is around Y, then around X, then 96 * around Y 97 */ 98 YXY("YXY", Vector3D.PLUS_J, Vector3D.PLUS_I, Vector3D.PLUS_J), 99 100 /** Set of Euler angles. 101 * this ordered set of rotations is around Y, then around Z, then 102 * around Y 103 */ 104 YZY("YZY", Vector3D.PLUS_J, Vector3D.PLUS_K, Vector3D.PLUS_J), 105 106 /** Set of Euler angles. 107 * this ordered set of rotations is around Z, then around X, then 108 * around Z 109 */ 110 ZXZ("ZXZ", Vector3D.PLUS_K, Vector3D.PLUS_I, Vector3D.PLUS_K), 111 112 /** Set of Euler angles. 113 * this ordered set of rotations is around Z, then around Y, then 114 * around Z 115 */ 116 ZYZ("ZYZ", Vector3D.PLUS_K, Vector3D.PLUS_J, Vector3D.PLUS_K); 117 118 /** Codes map. */ 119 private static final Map<String, RotationOrder> CODES_MAP = new HashMap<>(); 120 static { 121 for (final RotationOrder type : values()) { 122 CODES_MAP.put(type.toString(), type); 123 } 124 } 125 126 /** Name of the rotations order. */ 127 private final String name; 128 129 /** Axis of the first rotation. */ 130 private final Vector3D a1; 131 132 /** Axis of the second rotation. */ 133 private final Vector3D a2; 134 135 /** Axis of the third rotation. */ 136 private final Vector3D a3; 137 138 /** Private constructor. 139 * This is a utility class that cannot be instantiated by the user, 140 * so its only constructor is private. 141 * @param name name of the rotation order 142 * @param a1 axis of the first rotation 143 * @param a2 axis of the second rotation 144 * @param a3 axis of the third rotation 145 */ 146 RotationOrder(final String name, final Vector3D a1, final Vector3D a2, final Vector3D a3) { 147 this.name = name; 148 this.a1 = a1; 149 this.a2 = a2; 150 this.a3 = a3; 151 } 152 153 /** Get a string representation of the instance. 154 * @return a string representation of the instance (in fact, its name) 155 */ 156 @Override 157 public String toString() { 158 return name; 159 } 160 161 /** Get the axis of the first rotation. 162 * @return axis of the first rotation 163 */ 164 public Vector3D getA1() { 165 return a1; 166 } 167 168 /** Get the axis of the second rotation. 169 * @return axis of the second rotation 170 */ 171 public Vector3D getA2() { 172 return a2; 173 } 174 175 /** Get the axis of the second rotation. 176 * @return axis of the second rotation 177 */ 178 public Vector3D getA3() { 179 return a3; 180 } 181 182 /** 183 * Get the rotation order corresponding to a string representation. 184 * @param value name 185 * @return a rotation order object 186 * @since 1.7 187 */ 188 public static RotationOrder getRotationOrder(final String value) { 189 final RotationOrder type = CODES_MAP.get(value); 190 if (type == null) { 191 // Invalid value. An exception is thrown 192 throw new MathIllegalStateException(LocalizedGeometryFormats.INVALID_ROTATION_ORDER_NAME, value); 193 } 194 return type; 195 } 196 197 }