AxisSequence.java

  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. import org.apache.commons.geometry.euclidean.threed.Vector3D;

  19. /** Enum containing rotation axis sequences for use in defining 3 dimensional rotations.
  20.  */
  21. public enum AxisSequence {

  22.     /** Set of Tait-Bryan angles around the <strong>X</strong>, <strong>Y</strong>, and
  23.      * <strong>Z</strong> axes in that order.
  24.      */
  25.     XYZ(AxisSequenceType.TAIT_BRYAN, Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_Z),

  26.     /** Set of Tait-Bryan angles around the <strong>X</strong>, <strong>Z</strong>, and
  27.      * <strong>Y</strong> axes in that order.
  28.      */
  29.     XZY(AxisSequenceType.TAIT_BRYAN, Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_Y),

  30.     /** Set of Tait-Bryan angles around the <strong>Y</strong>, <strong>X</strong>, and
  31.      * <strong>Z</strong> axes in that order.
  32.      */
  33.     YXZ(AxisSequenceType.TAIT_BRYAN, Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Z),

  34.     /** Set of Tait-Bryan angles around the <strong>Y</strong>, <strong>Z</strong>, and
  35.      * <strong>X</strong> axes in that order.
  36.      */
  37.     YZX(AxisSequenceType.TAIT_BRYAN, Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_X),

  38.     /** Set of Cardan angles.
  39.      * this ordered set of rotations is around Z, then around X, then
  40.      * around Y
  41.      */
  42.     ZXY(AxisSequenceType.TAIT_BRYAN, Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Y),

  43.     /** Set of Tait-Bryan angles around the <strong>Z</strong>, <strong>Y</strong>, and
  44.      * <strong>X</strong> axes in that order.
  45.      */
  46.     ZYX(AxisSequenceType.TAIT_BRYAN, Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_X),

  47.     /** Set of Euler angles around the <strong>X</strong>, <strong>Y</strong>, and
  48.      * <strong>X</strong> axes in that order.
  49.      */
  50.     XYX(AxisSequenceType.EULER, Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_X),

  51.     /** Set of Euler angles around the <strong>X</strong>, <strong>Z</strong>, and
  52.      * <strong>X</strong> axes in that order.
  53.      */
  54.     XZX(AxisSequenceType.EULER, Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_X),

  55.     /** Set of Euler angles around the <strong>Y</strong>, <strong>X</strong>, and
  56.      * <strong>Y</strong> axes in that order.
  57.      */
  58.     YXY(AxisSequenceType.EULER, Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Y),

  59.     /** Set of Euler angles around the <strong>Y</strong>, <strong>Z</strong>, and
  60.      * <strong>Y</strong> axes in that order.
  61.      */
  62.     YZY(AxisSequenceType.EULER, Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_Y),

  63.     /** Set of Euler angles around the <strong>Z</strong>, <strong>X</strong>, and
  64.      * <strong>Z</strong> axes in that order.
  65.      */
  66.     ZXZ(AxisSequenceType.EULER, Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_X, Vector3D.Unit.PLUS_Z),

  67.     /** Set of Euler angles around the <strong>Z</strong>, <strong>Y</strong>, and
  68.      * <strong>Z</strong> axes in that order.
  69.      */
  70.     ZYZ(AxisSequenceType.EULER, Vector3D.Unit.PLUS_Z, Vector3D.Unit.PLUS_Y, Vector3D.Unit.PLUS_Z);

  71.     /** The type of axis sequence. */
  72.     private final AxisSequenceType type;

  73.     /** Axis of the first rotation. */
  74.     private final Vector3D axis1;

  75.     /** Axis of the second rotation. */
  76.     private final Vector3D axis2;

  77.     /** Axis of the third rotation. */
  78.     private final Vector3D axis3;

  79.     /** Simple constructor.
  80.      * @param type the axis sequence type
  81.      * @param axis1 first rotation axis
  82.      * @param axis2 second rotation axis
  83.      * @param axis3 third rotation axis
  84.      */
  85.     AxisSequence(final AxisSequenceType type, final Vector3D axis1, final Vector3D axis2, final Vector3D axis3) {
  86.         this.type = type;

  87.         this.axis1 = axis1;
  88.         this.axis2 = axis2;
  89.         this.axis3 = axis3;
  90.     }

  91.     /** Get the axis sequence type.
  92.      * @return the axis sequence type
  93.      */
  94.     public AxisSequenceType getType() {
  95.         return type;
  96.     }

  97.     /** Get the first rotation axis.
  98.      * @return the first rotation axis
  99.      */
  100.     public Vector3D getAxis1() {
  101.         return axis1;
  102.     }

  103.     /** Get the second rotation axis.
  104.      * @return the second rotation axis
  105.      */
  106.     public Vector3D getAxis2() {
  107.         return axis2;
  108.     }

  109.     /** Get the third rotation axis.
  110.      * @return the third rotation axis
  111.      */
  112.     public Vector3D getAxis3() {
  113.         return axis3;
  114.     }

  115.     /** Get an array containing the 3 rotation axes in order.
  116.      * @return a 3-element array containing the rotation axes in order
  117.      */
  118.     public Vector3D[] toArray() {
  119.         return new Vector3D[]{axis1, axis2, axis3};
  120.     }
  121. }