Class Matrix3DTransformation

java.lang.Object
org.opensourcephysics.numerics.Matrix3DTransformation
All Implemented Interfaces:
Cloneable, MatrixTransformation, Transformation

public class Matrix3DTransformation extends Object implements MatrixTransformation
Matrix3DTransformation implements 3D affine transformations using a matrix representation.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected static class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected double[][]
     
    protected double[][]
     
    protected double[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Matrix3DTransformation(double[][] matrix)
    Constructs a 3D transformation using the given matrix.
  • Method Summary

    Modifier and Type
    Method
    Description
    Provides a copy of this transformation.
    createAlignmentTransformation(double[] v1, double[] v2)
    Instantiates a rotation that aligns the first vector with the second vector.
    double[]
    direct(double[] point)
    Transforms the given point+.
    double[][]
    direct(double[][] mat)
    Transforms the given matrix into the transformation's coordinate system.
    final double[]
    getFlatMatrix(double[] mat)
    Gets the direct homogeneous affine transformation flattened into a 1-d array.
     
    double[]
     
    final double[]
    Gets the direct homogeneous affine transformation flattened into a 1-d array, ordered left to right, top to bottom If the mat parameter is null a double[16] array is created; otherwise the given array is used.
    double[]
    inverse(double[] point)
    Transforms the given point using the inverse transformation (if it exists).
    double[][]
    inverse(double[][] mat)
    Transforms the given matrix from the transformation's coordinate system.
    final void
    multiply(double[][] mat)
    Multiplies this rotation matrix by the given matrix from the right.
    final void
    Multiplies (concatenates) this transformation matrix with the given transformation.
    Quaternion(double[] quaternion)
    Creates an transformation representing a rotation about the origin by the given quaternion.
    Quaternion(double q0, double q1, double q2, double q3)
    Creates an AffineMatrix representing a rotation about the origin by the given quaternion components.
    rotation(double theta, double[] axis)
    Creates a 3D transforamtion representing a rotation about the origin by the given angle around the given axis.
    rotationX(double theta)
    Creates a 3D transforamtion representing a rotation about the x axis by the given angle.
    rotationY(double theta)
    Creates a 3D transforamtion representing a rotation about the y axis by the given angle.
    rotationZ(double theta)
    Creates a 3D transforamtion representing a rotation about the z axis by the given angle.
    boolean
    setMatrix(double[] newMatrix)
    Sets the matrix array of the rotation
    boolean
    setMatrix(double[][] newMatrix)
    Sets the double[][] matrix array of the rotation
    double[]
    setOrigin(double[] origin)
    Sets the origin for this rotation.
    void
    setOrigin(double ox, double oy, double oz)
    Sets the origin for this rotation.
    final double[]
    toQuaternion(double[] q)
     

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • origin

      protected double[] origin
    • matrix

      protected double[][] matrix
    • inverseMatrix

      protected double[][] inverseMatrix
  • Constructor Details

    • Matrix3DTransformation

      public Matrix3DTransformation(double[][] matrix)
      Constructs a 3D transformation using the given matrix. Affine transformations can be applied to 3D coordinates. A 3 by 3 matrix sets the rotation and shear. A null matrix sets the transformation to the identity transformation.
      Parameters:
      matrix - double[][]
  • Method Details

    • rotationX

      public static Matrix3DTransformation rotationX(double theta)
      Creates a 3D transforamtion representing a rotation about the x axis by the given angle.
      Parameters:
      theta - double
      Returns:
      Affine3DTransformation
    • rotationY

      public static Matrix3DTransformation rotationY(double theta)
      Creates a 3D transforamtion representing a rotation about the y axis by the given angle.
      Parameters:
      theta - double
      Returns:
      Affine3DTransformation
    • rotationZ

      public static Matrix3DTransformation rotationZ(double theta)
      Creates a 3D transforamtion representing a rotation about the z axis by the given angle.
      Parameters:
      theta - double
      Returns:
      Affine3DTransformation
    • rotation

      public static Matrix3DTransformation rotation(double theta, double[] axis)
      Creates a 3D transforamtion representing a rotation about the origin by the given angle around the given axis.
      Parameters:
      theta - double
      axis - double[]
      Returns:
      Affine3DTransformation
    • Quaternion

      public static Matrix3DTransformation Quaternion(double[] quaternion)
      Creates an transformation representing a rotation about the origin by the given quaternion.
      Parameters:
      quaternion - double[]
      Returns:
      Affine3DTransformation
    • Quaternion

      public static Matrix3DTransformation Quaternion(double q0, double q1, double q2, double q3)
      Creates an AffineMatrix representing a rotation about the origin by the given quaternion components.
      Parameters:
      q0 -
      q1 -
      q2 -
      q3 -
      Returns:
      Affine3DTransformation
    • setMatrix

      public boolean setMatrix(double[][] newMatrix)
      Sets the double[][] matrix array of the rotation
      Parameters:
      newMatrix -
    • setMatrix

      public boolean setMatrix(double[] newMatrix)
      Sets the matrix array of the rotation
      Parameters:
      matrix - a double[9] array with the matrix components in this order {m[0][0],m[0][1],m[0][2],m[1][0],...}
    • clone

      public Object clone()
      Provides a copy of this transformation.
      Specified by:
      clone in interface Transformation
      Overrides:
      clone in class Object
    • getFlatMatrix

      public final double[] getFlatMatrix(double[] mat)
      Gets the direct homogeneous affine transformation flattened into a 1-d array. If the mat parameter is null a double[16] array is created; otherwise the given array is used.
      Specified by:
      getFlatMatrix in interface MatrixTransformation
      Parameters:
      mat - double[] optional matrix
      Returns:
      double[] the matrix
    • getTransposedFlatMatrix

      public final double[] getTransposedFlatMatrix(double[] mat)
      Gets the direct homogeneous affine transformation flattened into a 1-d array, ordered left to right, top to bottom If the mat parameter is null a double[16] array is created; otherwise the given array is used.
      Parameters:
      mat - double[] optional matrix
      Returns:
      double[] the matrix
    • toQuaternion

      public final double[] toQuaternion(double[] q)
    • createAlignmentTransformation

      public static Matrix3DTransformation createAlignmentTransformation(double[] v1, double[] v2)
      Instantiates a rotation that aligns the first vector with the second vector.
      Parameters:
      v1 - double[]
      v2 - double[]
      Returns:
      Quaternion
    • setOrigin

      public void setOrigin(double ox, double oy, double oz)
      Sets the origin for this rotation.
      Parameters:
      ox - double
      oy - double
      oz - double
    • multiply

      public final void multiply(Matrix3DTransformation trans)
      Multiplies (concatenates) this transformation matrix with the given transformation.
      Parameters:
      trans - Matrix3DTransformation
    • multiply

      public final void multiply(double[][] mat)
      Multiplies this rotation matrix by the given matrix from the right.
      Parameters:
      mat - double[][]
    • setOrigin

      public double[] setOrigin(double[] origin)
      Sets the origin for this rotation.
      Parameters:
      origin - double[] the new origin
      Returns:
      double[]
    • direct

      public double[] direct(double[] point)
      Transforms the given point+.
      Specified by:
      direct in interface Transformation
      Parameters:
      point - the coordinates to be transformed
      Returns:
      double[] the transformed vector (i.e. point)
    • direct

      public double[][] direct(double[][] mat)
      Transforms the given matrix into the transformation's coordinate system.
      Parameters:
      matrix - to be transformed
    • inverse

      public double[] inverse(double[] point) throws UnsupportedOperationException
      Transforms the given point using the inverse transformation (if it exists). If the transformation is not invertible, then a call to this method must throw a UnsupportedOperationException exception.
      Specified by:
      inverse in interface Transformation
      Parameters:
      point - the coordinates to be transformed
      Returns:
      double[] the transformed vector (i.e. point)
      Throws:
      UnsupportedOperationException - If the transformation is not invertible
    • inverse

      public double[][] inverse(double[][] mat)
      Transforms the given matrix from the transformation's coordinate system.
      Parameters:
      matrix - to be transformed
    • getOrigin

      public double[] getOrigin()
    • getLoader

      public static XML.ObjectLoader getLoader()