Class Matrix2DTransformation

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

public class Matrix2DTransformation extends Object implements MatrixTransformation
Matrix2DTransformation implements 2D affine transformations
  • Constructor Details

    • Matrix2DTransformation

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

      public Matrix2DTransformation(AffineTransform transform)
      Constructor Matrix2DTransformation
      Parameters:
      transform -
  • Method Details

    • rotation

      public static Matrix2DTransformation rotation(double theta)
      Creates a 2D transformation representing a rotation about the origin by the given angle.
      Parameters:
      theta - double
      Returns:
      Matrix2DTransformation
    • rotation

      public static Matrix2DTransformation rotation(double theta, double anchorx, double anchory)
      Creates a 2D transformation representing a rotation about the origin by the given angle around the given axis.
      Parameters:
      theta - double
      anchorx - double
      anchory - double
      Returns:
      Matrix2DTransformation
    • getTotalTransform

      public AffineTransform getTotalTransform()
    • 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 arrray. If the mat parameter is null a double[6] array is created; otherwise the given array is used.
      Specified by:
      getFlatMatrix in interface MatrixTransformation
      Parameters:
      mat - double[] optional matrix
      Returns:
      double[] the matrix
    • createAlignmentTransformation

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

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

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

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

      public final void multiply(double[][] mat)
      Multiplies this rotation matrix by the given matrix.
      Parameters:
      mat - 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)
    • 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
    • getLoader

      public static XML.ObjectLoader getLoader()