Class AffineTransformation3D

java.lang.Object
com.irurueta.geometry.Transformation3D
com.irurueta.geometry.AffineTransformation3D
All Implemented Interfaces:
Serializable

public class AffineTransformation3D extends Transformation3D implements Serializable
This class performs affine transformations on 3D space. Affine transformations include transformations related to rotations, translations, independently scaling horizontal or vertical coordinates or skewing the coordinates axis. This class is not intended to be used on points located at infinity or at very large coordinates, since numerical instabilities may occur. For those cases use a ProjectiveTransformation3D instead.
See Also:
  • Field Details

    • NUM_TRANSLATION_COORDS

      public static final int NUM_TRANSLATION_COORDS
      Constant indicating number of coordinates required in translation arrays.
      See Also:
    • INHOM_COORDS

      public static final int INHOM_COORDS
      Constant defining number of inhomogeneous coordinates in 3D space.
      See Also:
    • HOM_COORDS

      public static final int HOM_COORDS
      Constant defining number of homogeneous coordinates in 3D space.
      See Also:
    • a

      private com.irurueta.algebra.Matrix a
      Linear mapping.
    • translation

      private double[] translation
      2D translation to be performed on geometric objects. Translation is specified using inhomogeneous coordinates.
  • Constructor Details

    • AffineTransformation3D

      public AffineTransformation3D()
      Empty constructor. Creates transformation that has no effect.
    • AffineTransformation3D

      public AffineTransformation3D(com.irurueta.algebra.Matrix a)
      Creates transformation with provided rotation.
      Parameters:
      a - linear mapping.
      Throws:
      NullPointerException - raised if provided rotation is null.
      IllegalArgumentException - raised if provided matrix does not have size 3x3.
    • AffineTransformation3D

      public AffineTransformation3D(double scale)
      Creates transformation with provided scale value.
      Parameters:
      scale - scale value. Values between 0.0 and 1.0 reduce objects, values greater than 1.0 enlarge objects and negative values reverse objects.
    • AffineTransformation3D

      public AffineTransformation3D(Rotation3D rotation)
      Creates transformation with provided rotation.
      Parameters:
      rotation - a 3D rotation.
      Throws:
      NullPointerException - raised if provided rotation is null.
    • AffineTransformation3D

      public AffineTransformation3D(double scale, Rotation3D rotation)
      Creates transformation with provided scale and rotation.
      Parameters:
      scale - scale value. Values between 0.0 and 1.0 reduce objects, values greater than 1.0 enlarge objects and negative values reverse objects.
      rotation - a 3D rotation.
      Throws:
      NullPointerException - raised if provided rotation is null.
    • AffineTransformation3D

      public AffineTransformation3D(AffineParameters3D params, Rotation3D rotation)
      Creates transformation with provided affine parameters and rotation.
      Parameters:
      params - Affine parameters including horizontal scaling, vertical scaling and skewness.
      rotation - a 3D rotation.
      Throws:
      NullPointerException - raised if provided parameters are null or if provided rotation is null.
    • AffineTransformation3D

      public AffineTransformation3D(double[] translation)
      Creates transformation with provided 3D translation.
      Parameters:
      translation - array indicating 3D translation using inhomogeneous coordinates.
      Throws:
      NullPointerException - raised if provided array is null.
      IllegalArgumentException - raised if length of array is not equal to NUM_TRANSLATION_COORDS.
    • AffineTransformation3D

      public AffineTransformation3D(com.irurueta.algebra.Matrix a, double[] translation)
      Creates transformation with provided rotation, translation and scale value.
      Parameters:
      a - linear mapping.
      translation - array indicating 3D translation using inhomogeneous coordinates.
      Throws:
      NullPointerException - raised if provided array is null or if linear mapping is null.
      IllegalArgumentException - Raised if length of array is not equal to NUM_TRANSLATION_COORDS.
    • AffineTransformation3D

      public AffineTransformation3D(double scale, double[] translation)
      Creates transformation with provided scale and translation.
      Parameters:
      scale - Scale value. Values between 0.0 and 1.0 reduce objects, values greater than 1.0 enlarge objects and negative values reverse objects.
      translation - Array indicating 3D translation using inhomogeneous coordinates.
      Throws:
      NullPointerException - raised if provided translation is null.
      IllegalArgumentException - Raised if provided translation does not have length 3.
    • AffineTransformation3D

      public AffineTransformation3D(Rotation3D rotation, double[] translation)
      Creates transformation with provided rotation and translation.
      Parameters:
      rotation - a 3D rotation.
      translation - array indicating 3D translation using inhomogeneous coordinates.
      Throws:
      NullPointerException - raised if provided rotation or translation is null.
      IllegalArgumentException - raised if provided translation does not have length 3.
    • AffineTransformation3D

      public AffineTransformation3D(double scale, Rotation3D rotation, double[] translation)
      Creates transformation with provided scale, rotation and translation.
      Parameters:
      scale - Scale value. Values between 0.0 and 1.0 reduce objects, values greater than 1.0 enlarge objects and negative values reverse objects.
      rotation - a 3D rotation.
      translation - array indicating 3D translation using inhomogeneous coordinates.
      Throws:
      NullPointerException - raised if provided rotation or translation is null.
      IllegalArgumentException - raised if provided translation does not have length 3.
    • AffineTransformation3D

      public AffineTransformation3D(AffineParameters3D params, Rotation3D rotation, double[] translation)
      Creates transformation with provided parameters, rotation and translation.
      Parameters:
      params - affine parameters including horizontal scaling, vertical scaling and skewness.
      rotation - a 3D rotation.
      translation - array indicating 3D translation using inhomogeneous coordinates.
      Throws:
      NullPointerException - raised if provided parameters, rotation or translation is null.
      IllegalArgumentException - raised if provided translation does not have length 3.
    • AffineTransformation3D

      public AffineTransformation3D(Point3D inputPoint1, Point3D inputPoint2, Point3D inputPoint3, Point3D inputPoint4, Point3D outputPoint1, Point3D outputPoint2, Point3D outputPoint3, Point3D outputPoint4) throws CoincidentPointsException
      Creates transformation by estimating its internal values using provided 4 corresponding original and transformed points.
      Parameters:
      inputPoint1 - 1st input point.
      inputPoint2 - 2nd input point.
      inputPoint3 - 3rd input point.
      inputPoint4 - 4th input point.
      outputPoint1 - 1st transformed point corresponding to 1st input point.
      outputPoint2 - 2nd transformed point corresponding to 2nd input point.
      outputPoint3 - 3rd transformed point corresponding to 3rd input point.
      outputPoint4 - 4th transformed point corresponding to 4th input point.
      Throws:
      CoincidentPointsException - raised if transformation cannot be estimated for some reason (point configuration degeneracy, duplicate points or numerical instabilities).
    • AffineTransformation3D

      public AffineTransformation3D(Plane inputPlane1, Plane inputPlane2, Plane inputPlane3, Plane inputPlane4, Plane outputPlane1, Plane outputPlane2, Plane outputPlane3, Plane outputPlane4) throws CoincidentPlanesException
      Creates transformation by estimating its internal values using provided 4 corresponding original and transformed planes.
      Parameters:
      inputPlane1 - 1st input plane.
      inputPlane2 - 2nd input plane.
      inputPlane3 - 3rd input plane.
      inputPlane4 - 4th input plane.
      outputPlane1 - 1st transformed plane corresponding to 1st input plane.
      outputPlane2 - 2nd transformed plane corresponding to 2nd input plane.
      outputPlane3 - 3rd transformed plane corresponding to 3rd input plane.
      outputPlane4 - 4th transformed plane corresponding to 4th input plane.
      Throws:
      CoincidentPlanesException - raised if transformation cannot be estimated for some reason (plane configuration degeneracy, duplicate planes or numerical instabilities).
    • AffineTransformation3D

      public AffineTransformation3D(Line3D inputLine1, Line3D inputLine2, Line3D outputLine1, Line3D outputLine2) throws CoincidentLinesException
      Creates transformation by estimating internal parameters using provided 2 corresponding original and transformed lines.
      Parameters:
      inputLine1 - 1st input line.
      inputLine2 - 2nd input line.
      outputLine1 - 1st transformed line corresponding to 1st input line.
      outputLine2 - 2nd transformed line corresponding to 2nd input line.
      Throws:
      CoincidentLinesException - raised if transformation cannot be estimated for some reason (line configuration degeneracy, duplicate lines or numerical instabilities).
  • Method Details

    • getA

      public com.irurueta.algebra.Matrix getA()
      Returns linear mapping matrix to perform affine transformation. Point transformation is computed as a * x + t, where x is a point and t is the amount of translation.
      Returns:
      linear mapping matrix.
    • setA

      public final void setA(com.irurueta.algebra.Matrix a)
      Sets linear mapping matrix to perform affine transformation.
      Parameters:
      a - linear mapping matrix.
      Throws:
      NullPointerException - raised if provided matrix is null.
      IllegalArgumentException - raised if provided matrix does not have size 3x3.
    • getRotation

      public Rotation3D getRotation() throws com.irurueta.algebra.AlgebraException
      Returns 3D rotation assigned to this transformation. Note: if this rotation instance is modified, its changes won't be reflected on this instance until rotation is set again.
      Returns:
      3D rotation.
      Throws:
      com.irurueta.algebra.AlgebraException - if for some reason rotation cannot be estimated (usually because of numerical instability).
    • setRotation

      public void setRotation(Rotation3D rotation) throws com.irurueta.algebra.AlgebraException
      Sets 3D rotation for this transformation.
      Parameters:
      rotation - a 3D rotation.
      Throws:
      NullPointerException - raised if provided rotation is null.
      com.irurueta.algebra.AlgebraException - raised if for numerical reasons rotation cannot be set (usually because of numerical instability in parameters of this transformation).
    • addRotation

      public void addRotation(Rotation3D rotation) throws com.irurueta.algebra.AlgebraException
      Adds provided rotation to current rotation assigned to this transformation.
      Parameters:
      rotation - 3D rotation to be added.
      Throws:
      com.irurueta.algebra.AlgebraException - raised if for numerical reasons rotation cannot be set (usually because of numerical instability in parameters of this transformation).
    • setScale

      public void setScale(double scale) throws com.irurueta.algebra.AlgebraException
      Sets scale of this transformation.
      Parameters:
      scale - scale value to be set. a value between 0.0 and 1.0 indicates that objects will be reduced, a value greater than 1.0 indicates that objects will be enlarged, and a negative value indicates that objects will be reversed.
      Throws:
      com.irurueta.algebra.AlgebraException - raised if for numerical reasons scale cannot be set (usually because of numerical instability in parameters of this transformation).
    • getParameters

      public AffineParameters3D getParameters() throws com.irurueta.algebra.AlgebraException
      Gets affine parameters of this instance. Affine parameters contain horizontal scale, vertical scale and skewness of axes.
      Returns:
      affine parameters.
      Throws:
      com.irurueta.algebra.AlgebraException - raised if for numerical reasons affine parameters cannot be retrieved (usually because of numerical instability in matrix a).
    • getParameters

      public void getParameters(AffineParameters3D result) throws com.irurueta.algebra.AlgebraException
      Computes affine parameters of this instance and stores the result in provided instance. Affine parameters contain horizontal scale, vertical scale and skewness of axes.
      Parameters:
      result - instance where affine parameters will be stored.
      Throws:
      com.irurueta.algebra.AlgebraException - raised if for numerical reasons affine parameters cannot be retrieved (usually because of numerical instability in matrix a).
    • setParameters

      public void setParameters(AffineParameters3D parameters) throws com.irurueta.algebra.AlgebraException
      Sets affine parameters of this instance. Affine parameters contain horizontal scale, vertical scale and skewness of axes.
      Parameters:
      parameters - affine parameters to be set.
      Throws:
      com.irurueta.algebra.AlgebraException - raised if for numerical reasons affine parameters cannot be set (usually because of numerical instability in current matrix a).
    • getTranslation

      public double[] getTranslation()
      Returns 3D translation assigned to this transformation as an array expressed in inhomogeneous coordinates.
      Returns:
      3D translation array.
    • setTranslation

      public void setTranslation(double[] translation)
      Sets 3D translation assigned to this transformation as an array expressed in inhomogeneous coordinates.
      Parameters:
      translation - 3D translation array.
      Throws:
      IllegalArgumentException - Raised if provided array does not have length equal to NUM_TRANSLATION_COORDS.
    • addTranslation

      public void addTranslation(double[] translation)
      Adds provided translation to current translation on this transformation. Provided translation must be expressed as an array of inhomogeneous coordinates.
      Parameters:
      translation - 3D translation array.
      Throws:
      IllegalArgumentException - Raised if provided array does not have length equal to NUM_TRANSLATION_COORDS.
    • getTranslationX

      public double getTranslationX()
      Returns current x coordinate translation assigned to this transformation.
      Returns:
      X coordinate translation.
    • setTranslationX

      public void setTranslationX(double translationX)
      Sets x coordinate translation to be made by this transformation.
      Parameters:
      translationX - X coordinate translation to be set.
    • getTranslationY

      public double getTranslationY()
      Returns current y coordinate translation assigned to this transformation.
      Returns:
      Y coordinate translation.
    • setTranslationY

      public void setTranslationY(double translationY)
      Sets y coordinate translation to be made by this transformation.
      Parameters:
      translationY - Y coordinate translation to be set.
    • getTranslationZ

      public double getTranslationZ()
      Returns current z coordinate translation assigned to this transformation.
      Returns:
      Z coordinate translation.
    • setTranslationZ

      public void setTranslationZ(double translationZ)
      Sets z coordinate translation to be made by this transformation.
      Parameters:
      translationZ - z coordinate translation to be set.
    • setTranslation

      public void setTranslation(double translationX, double translationY, double translationZ)
      Sets x, y, z coordinates of translation to be made by this transformation.
      Parameters:
      translationX - translation x coordinate to be set.
      translationY - translation y coordinate to be set.
      translationZ - translation z coordinate to be set.
    • setTranslation

      public void setTranslation(Point3D translation)
      Sets x, y, z coordinates of translation to be made by this transformation.
      Parameters:
      translation - translation to be set.
    • getTranslationPoint

      public Point3D getTranslationPoint()
      Gets x, y, z coordinates of translation to be made by this transformation as a new point.
      Returns:
      a new point containing translation coordinates.
    • getTranslationPoint

      public void getTranslationPoint(Point3D out)
      Gets x, y, z coordinates of translation to be made by this transformation and stores them into provided point.
      Parameters:
      out - point where translation coordinates will be stored.
    • addTranslationX

      public void addTranslationX(double translationX)
      Adds provided x coordinate to current translation assigned to this transformation.
      Parameters:
      translationX - X coordinate to be added to current translation.
    • addTranslationY

      public void addTranslationY(double translationY)
      Adds provided y coordinate to current translation assigned to this transformation.
      Parameters:
      translationY - Y coordinate to be added to current translation.
    • addTranslationZ

      public void addTranslationZ(double translationZ)
      Adds provided z coordinate to current translation assigned to this transformation.
      Parameters:
      translationZ - Z coordinate to be added to current translation.
    • addTranslation

      public void addTranslation(double translationX, double translationY, double translationZ)
      Adds provided coordinates to current translation assigned to this transformation.
      Parameters:
      translationX - x coordinate to be added to current translation.
      translationY - y coordinate to be added to current translation.
      translationZ - z coordinate to be added to current translation.
    • addTranslation

      public void addTranslation(Point3D translation)
      Adds provided coordinates to current translation assigned to this transformation.
      Parameters:
      translation - x, y, z coordinates to be added to current translation.
    • asMatrix

      public com.irurueta.algebra.Matrix asMatrix()
      Represents this transformation as a 4x4 matrix. a point can be transformed as T * p, where T is the transformation matrix and p is a point expressed as an homogeneous vector.
      Specified by:
      asMatrix in class Transformation3D
      Returns:
      This transformation in matrix form.
    • asMatrix

      public void asMatrix(com.irurueta.algebra.Matrix m)
      Represents this transformation as a 4x4 matrix and stores the result in provided instance.
      Specified by:
      asMatrix in class Transformation3D
      Parameters:
      m - instance where transformation matrix will be stored.
      Throws:
      IllegalArgumentException - raised if provided instance is not a 4x4 matrix.
    • transform

      public void transform(Point3D inputPoint, Point3D outputPoint)
      Transforms input point using this transformation and stores the result in provided output points.
      Specified by:
      transform in class Transformation3D
      Parameters:
      inputPoint - point to be transformed.
      outputPoint - instance where transformed point data will be stored.
    • transform

      public void transform(Quadric inputQuadric, Quadric outputQuadric) throws NonSymmetricMatrixException, com.irurueta.algebra.AlgebraException
      Transforms a quadric using this transformation and stores the result into provided output quadric.
      Specified by:
      transform in class Transformation3D
      Parameters:
      inputQuadric - quadric to be transformed.
      outputQuadric - instance where data of transformed quadric will be stored.
      Throws:
      NonSymmetricMatrixException - raised if due to numerical precision the resulting output conic matrix is not considered to be symmetric.
      com.irurueta.algebra.AlgebraException - raised if transform cannot be computed because of numerical instabilities.
    • transform

      public void transform(DualQuadric inputDualQuadric, DualQuadric outputDualQuadric) throws NonSymmetricMatrixException
      Transforms a dual quadric using this transformation and stores the result into provided output dual quadric.
      Specified by:
      transform in class Transformation3D
      Parameters:
      inputDualQuadric - dual quadric to be transformed.
      outputDualQuadric - instance where data of transformed dual quadric will be stored.
      Throws:
      NonSymmetricMatrixException - raised if due to numerical precision the resulting output dual conic matrix is not considered to be symmetric.
    • transform

      public void transform(Plane inputPlane, Plane outputPlane) throws com.irurueta.algebra.AlgebraException
      Transforms provided input plane using this transformation and stores the result into provided output plane instance.
      Specified by:
      transform in class Transformation3D
      Parameters:
      inputPlane - plane to be transformed.
      outputPlane - instance where data of transformed plane will be stored.
      Throws:
      com.irurueta.algebra.AlgebraException - raised if transformAndReturnNew cannot be computed because of numerical instabilities.
    • transform

      public void transform(PinholeCamera inputCamera, PinholeCamera outputCamera) throws com.irurueta.algebra.AlgebraException
      Transforms a camera using this transformation and stores the result into provided output camera.
      Specified by:
      transform in class Transformation3D
      Parameters:
      inputCamera - camera to be transformed.
      outputCamera - instance where data of transformed camera will be stored.
      Throws:
      com.irurueta.algebra.AlgebraException - raised if transform cannot be computed because of numerical instabilities.
    • inverse

      public void inverse() throws com.irurueta.algebra.AlgebraException
      Inverses this transformation.
      Throws:
      com.irurueta.algebra.AlgebraException - if inverse transform cannot be computed because of numerical instabilities.
    • inverseAndReturnNew

      public Transformation3D inverseAndReturnNew() throws com.irurueta.algebra.AlgebraException
      Computes the inverse of this transformation and returns the result as a new transformation instance.
      Returns:
      inverse transformation.
      Throws:
      com.irurueta.algebra.AlgebraException - if inverse transform cannot be computed because of numerical instabilities.
    • inverse

      public void inverse(AffineTransformation3D result) throws com.irurueta.algebra.AlgebraException
      Computes the inverse of this transformation and stores the result in provided instance.
      Parameters:
      result - instance where inverse transformation will be stored.
      Throws:
      com.irurueta.algebra.AlgebraException - if inverse transform cannot be computed because of numerical instabilities.
    • toProjective

      public ProjectiveTransformation3D toProjective()
      Converts this transformation into a metric transformation.
      Returns:
      This transformation converted into a projective transformation.
    • combine

      public void combine(AffineTransformation3D transformation)
      Combines this transformation with provided transformation. The combination is equivalent to multiplying the matrix of this transformation with the matrix of provided transformation.
      Parameters:
      transformation - Transformation to be combined with.
    • combineAndReturnNew

      public AffineTransformation3D combineAndReturnNew(AffineTransformation3D transformation)
      Combines this transformation with provided transformation and returns the result as a new transformation instance. The combination is equivalent to multiplying the matrix of this transformation with the matrix of provided transformation.
      Parameters:
      transformation - Transformation to be combined with.
      Returns:
      a new transformation resulting of the combination with this transformation and provided transformation.
    • combine

      private void combine(AffineTransformation3D inputTransformation, AffineTransformation3D outputTransformation)
      Combines this transformation with provided input transformation and stores the result into provided output transformation. The combination is equivalent to multiplying the matrix of this transformation with the matrix of provided input transformation.
      Parameters:
      inputTransformation - transformation to be combined with.
      outputTransformation - transformation where result will be stored.
    • setTransformationFromPoints

      public final void setTransformationFromPoints(Point3D inputPoint1, Point3D inputPoint2, Point3D inputPoint3, Point3D inputPoint4, Point3D outputPoint1, Point3D outputPoint2, Point3D outputPoint3, Point3D outputPoint4) throws CoincidentPointsException
      Estimates this transformation internal parameters by using 4 corresponding original and transformed points.
      Parameters:
      inputPoint1 - 1st input point.
      inputPoint2 - 2nd input point.
      inputPoint3 - 3rd input point.
      inputPoint4 - 4th input point.
      outputPoint1 - 1st transformed point corresponding to 1st input point.
      outputPoint2 - 2nd transformed point corresponding to 2nd input point.
      outputPoint3 - 3rd transformed point corresponding to 3rd input point.
      outputPoint4 - 4th transformed point corresponding to 4th input point.
      Throws:
      CoincidentPointsException - raised if transformation cannot be estimated for some reason (point configuration degeneracy, duplicate points or numerical instabilities).
    • setTransformationFromPlanes

      public final void setTransformationFromPlanes(Plane inputPlane1, Plane inputPlane2, Plane inputPlane3, Plane inputPlane4, Plane outputPlane1, Plane outputPlane2, Plane outputPlane3, Plane outputPlane4) throws CoincidentPlanesException
      Estimates this transformation internal parameters by using 4 corresponding original and transformed planes.
      Parameters:
      inputPlane1 - 1st input plane.
      inputPlane2 - 2nd input plane.
      inputPlane3 - 3rd input plane.
      inputPlane4 - 4th input plane.
      outputPlane1 - 1st transformed plane corresponding to 1st input plane.
      outputPlane2 - 2nd transformed plane corresponding to 2nd input plane.
      outputPlane3 - 3rd transformed plane corresponding to 3rd input plane.
      outputPlane4 - 4th transformed plane corresponding to 4th input plane.
      Throws:
      CoincidentPlanesException - raised if transformation cannot be estimated for some reason (plane configuration degeneracy, duplicate points or numerical instabilities).
    • setTransformationFromLines

      public final void setTransformationFromLines(Line3D inputLine1, Line3D inputLine2, Line3D outputLine1, Line3D outputLine2) throws CoincidentLinesException
      Estimates this transformation internal parameters by using provided 2 corresponding original and transformed lines.
      Parameters:
      inputLine1 - 1st input line.
      inputLine2 - 2nd input line.
      outputLine1 - 1st transformed line corresponding to 1st input line.
      outputLine2 - 2nd transformed line corresponding to 2nd input line.
      Throws:
      CoincidentLinesException - Raised if transformation cannot be estimated for some reason (line configuration degeneracy, duplicate lines or numerical instabilities).