Class Transformation3D

java.lang.Object
org.jlab.geom.prim.Transformation3D
All Implemented Interfaces:
Showable

public class Transformation3D extends Object implements Showable
A sequence of rotations and translations that can be performed on a objects implementing the Transformable interface.

To use Transformation3D object to rotate and translate a Transformable object, use the apply(org.jlab.geom.prim.Transformable) method.

If a Transformation3D object is constructed with no arguments, then it will contain no transformations and will in essence represent an identity transformation aka do-nothing transformation.

The translateXYZ(double, double, double), rotateX(double), rotateY(double), rotateZ(double), and append(Transformation3D) methods all modify the object from which they are invoked, but these functions also return a copy of the object so that rotations and translations can be chained together and written on a single line.

Ex.
  Transformation3D() xform = new Transformation3D(); // identity
  xform.translateXYZ(100, 0, 20).rotateZ(Math.PI);

In this example, after the code has executed xform will be a transformation that first translates an object by x+100 and z+20, and then rotates the object by 180 degrees clockwise around the z-axis.

The inverse of a transformation can be obtained via inverse().

Ex.
  Transformation3D inv = xform.inverse();
  Point3D pt = new Point3D(3, 5, 7);
  xform.apply(pt);
  inv.apply(pt);

At the end of this example, pt should equal to (3, 5, 7), however extremely small rounding errors may be introduced due to the nature of floating point arithmetic (but no more than 1 ulp per coordinate per transformation).

Author:
jnhankins
  • Constructor Details

    • Transformation3D

      public Transformation3D()
      Constructs a new empty Transformation3D that is equivalent to an identity transformation.
    • Transformation3D

      public Transformation3D(Transformation3D transform)
      Constructs a new Transformation3D identical the the given transformation.
      Parameters:
      transform - the apply to copy
  • Method Details

    • copy

      public Transformation3D copy(Transformation3D transform)
      Sets this transformation to be equal to the given transformation.
      Parameters:
      transform - the transformation to copy
      Returns:
      a reference to this object
    • translateXYZ

      public Transformation3D translateXYZ(double dx, double dy, double dz)
      Appends a translation to this transformation.
      Parameters:
      dx - amount to translate along the x axis
      dy - amount to translate along the y axis
      dz - amount to translate along the z axis
      Returns:
      a reference to this object
    • rotateX

      public Transformation3D rotateX(double angle)
      Appends a clockwise rotation around the x axis to this transformation.
      Parameters:
      angle - rotation angle in radians
      Returns:
      a reference to this object
    • rotateY

      public Transformation3D rotateY(double angle)
      Appends a clockwise rotation around the y axis to this transformation.
      Parameters:
      angle - rotation angle in radians
      Returns:
      a reference to this object
    • rotateZ

      public Transformation3D rotateZ(double angle)
      Appends a clockwise rotation around the z axis to this transformation.
      Parameters:
      angle - rotation angle in radians
      Returns:
      a reference to this object
    • append

      Appends the given apply to this transformation.
      Parameters:
      trans - the apply to append
      Returns:
      a reference to this object
    • append

      public Transformation3D append(Transformation3D transformation)
      Appends a copy of the given transformation to this transformation.
      Parameters:
      transformation - the transformation append
      Returns:
      a reference to this object
    • apply

      public void apply(Transformable obj)
      Modifies the given Transformable object by applying the transformation represented by this Transformation3D to the given object.
      Parameters:
      obj - the object to apply this transformation to
    • clear

      public void clear()
      Resets this transformation by removing all of its transforms.
    • inverse

      public Transformation3D inverse()
      Constructs a new Transformation3D that is the inverse of this transformation.
      Returns:
      the inverse of this transformation
    • transformSequence

      public List<Transformation3D.Transform> transformSequence()
      Returns a reference to this Transformation3D's Transform sequence. Modifying the returned list will modify this Transformation3D.
      Returns:
      the transform sequence
    • show

      public void show()
      Invokes System.out.println(this).
      Specified by:
      show in interface Showable
    • toString

      public String toString()
      Overrides:
      toString in class Object