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 java.util.function.UnaryOperator;
    20
    21  import org.apache.commons.geometry.euclidean.threed.Vector3D;
    22
    23  /**
    24   * A collection of standard vector rotation operators implemented as
    25   * {@link UnaryOperator}s. These can be used to test rotation algorithms.
    26   */
    27  public final class StandardRotations {
    28
    29      /** The identity rotation; the input vector is returned unchanged. */
    30      public static final UnaryOperator<Vector3D> IDENTITY = v -> v;
    31
    32      /** Rotates {@code pi/2} around the {@code +x} axis */
    33      public static final UnaryOperator<Vector3D> PLUS_X_HALF_PI = v -> Vector3D.of(v.getX(), -v.getZ(), v.getY());
    34
    35      /** Rotates {@code pi/2} around the {@code -x} axis */
    36      public static final UnaryOperator<Vector3D> MINUS_X_HALF_PI = v -> Vector3D.of(v.getX(), v.getZ(), -v.getY());
    37
    38      /** Rotates {@code pi} around the {@code x} axis (+x and -x are the same) */
    39      public static final UnaryOperator<Vector3D> X_PI = v -> Vector3D.of(v.getX(), -v.getY(), -v.getZ());
    40
    41      /** Rotates {@code pi/2} around the {@code +y} axis */
    42      public static final UnaryOperator<Vector3D> PLUS_Y_HALF_PI = v -> Vector3D.of(v.getZ(), v.getY(), -v.getX());
    43
    44      /** Rotates {@code pi/2} around the {@code -y} axis */
    45      public static final UnaryOperator<Vector3D> MINUS_Y_HALF_PI = v -> Vector3D.of(-v.getZ(), v.getY(), v.getX());
    46
    47      /** Rotates {@code pi} around the {@code y} axis (+y and -y are the same) */
    48      public static final UnaryOperator<Vector3D> Y_PI = v -> Vector3D.of(-v.getX(), v.getY(), -v.getZ());
    49
    50      /** Rotates {@code pi/2} around the {@code -y} axis */
    51      public static final UnaryOperator<Vector3D> PLUS_Z_HALF_PI = v -> Vector3D.of(-v.getY(), v.getX(), v.getZ());
    52
    53      /** Rotates {@code pi/2} around the {@code -y} axis */
    54      public static final UnaryOperator<Vector3D> MINUS_Z_HALF_PI = v -> Vector3D.of(v.getY(), -v.getX(), v.getZ());
    55
    56      /** Rotates {@code pi} around the {@code y} axis (+y and -y are the same) */
    57      public static final UnaryOperator<Vector3D> Z_PI = v -> Vector3D.of(-v.getX(), -v.getY(), v.getZ());
    58
    59      /** Rotates {@code 2pi/3} around the {@code (1, 1, 1)} axis */
    60      public static final UnaryOperator<Vector3D> PLUS_DIAGONAL_TWO_THIRDS_PI = v ->
    61          Vector3D.of(v.getZ(), v.getX(), v.getY());
    62
    63      /** Rotates {@code 2pi/3} around the {@code (-1, -1, -1)} axis */
    64      public static final UnaryOperator<Vector3D> MINUS_DIAGONAL_TWO_THIRDS_PI = v ->
    65          Vector3D.of(v.getY(), v.getZ(), v.getX());
    66
    67      /** Private constructor. */
    68      private StandardRotations() {}
    69  }