de.jreality.math
Class MatrixBuilder

java.lang.Object
  extended by de.jreality.math.MatrixBuilder

public final class MatrixBuilder
extends java.lang.Object

This class wraps a Matrix instance for easy specification of concatenated operations.
All the static methods are factory methods that create an instance for a selected metric.
Note: the factory methods with Transformation as a parameter copy the underlying double[] and wrap the copy into a new Matrix instance - the factory methods that take a Matrix as a parameter simply work on the given Matrix. Finally, the factory methods without parameters create a new identity matrix to act on.

The instance methods which carry out matrix operations are always applyed on the right hand side of the current value of the matrix. All these methods return this instance as value, so that one can do many calls in a row.

 Matrix m = MatrixBuilder.euclidean()
            .translate(2,2,2)
            .rotate(Math.PI/2, 1, 1, 1)
            .scale(3,1,2)
            .getMatrix();
 
 SceneGraphComponent camCom = new SceneGraphComponent();
 MatrixBuilder.euclidean().translate(0,2,3)
              .rotateFromTo(new double[]{0,0,-1}, new double[]{0,-2,-3})
              .scale(2)
              .assignTo(camComp); // Transformation gets set and assigned
 
For explanation of metric, see P3.

Author:
weissman

Method Summary
 void assignTo(double[] array)
           
 void assignTo(Matrix m)
           
 void assignTo(SceneGraphComponent comp)
           
 void assignTo(Transformation trafo)
           
 MatrixBuilder conjugateBy(double[] c)
           
static MatrixBuilder elliptic()
          Create a matrix builder which generates isometries with respect to elliptic (or (4,0)) metric.
static MatrixBuilder elliptic(Matrix m)
           
static MatrixBuilder elliptic(SceneGraphComponent cmp)
           
static MatrixBuilder elliptic(Transformation m)
           
static MatrixBuilder euclidean()
          Create a matrix builder which generates isometries with respect to euclidean metric.
static MatrixBuilder euclidean(Matrix m)
           
static MatrixBuilder euclidean(SceneGraphComponent cmp)
           
static MatrixBuilder euclidean(Transformation m)
          Create a matrix builder which generates isometries with respect to euclidean metric.
 double[] getArray()
           
 Matrix getMatrix()
           
static MatrixBuilder hyperbolic()
          Create a matrix builder which generates isometries with respect to hyperbolic (or (3,1)) metric.
static MatrixBuilder hyperbolic(Matrix m)
           
static MatrixBuilder hyperbolic(SceneGraphComponent cmp)
           
static MatrixBuilder hyperbolic(Transformation m)
           
static MatrixBuilder init(Matrix m, int metric)
          This constructor accepts the metric as an argument.
static MatrixBuilder projective()
          Create a matrix builder which strictly speaking doesn't know about metric: purely projective.
static MatrixBuilder projective(Matrix m)
           
static MatrixBuilder projective(Transformation m)
           
 MatrixBuilder reflect(double[] plane)
          reflects the wrapped Matrix at the plane
 MatrixBuilder reflect(double[] v1, double[] v2, double[] v3)
          reflects the wrapped Matrix at the plane determined by the the given 3 points
 MatrixBuilder reset()
          assigns ID to the underlying matrix
 MatrixBuilder rotate(double[] p1, double[] p2, double angle)
          rotate about the axis through the points p1 and p2
 MatrixBuilder rotate(double angle, double[] axis)
           
 MatrixBuilder rotate(double angle, double axisX, double axisY, double axisZ)
           
 MatrixBuilder rotateFromTo(double[] v1, double[] v2)
          A rotation which takes vector v1 to vector v2.
 MatrixBuilder rotateX(double angle)
           
 MatrixBuilder rotateY(double angle)
           
 MatrixBuilder rotateZ(double angle)
           
 MatrixBuilder scale(double scale)
           
 MatrixBuilder scale(double[] scale)
           
 MatrixBuilder scale(double scaleX, double scaleY, double scaleZ)
           
 MatrixBuilder skew(int i, int j, double val)
           
 MatrixBuilder times(double[] array)
          multiplies array (considered as 4x4 matrix) on the right hand side
 MatrixBuilder times(Matrix matrix)
          multiplies the given Matrix on the right hand side
 MatrixBuilder translate(double[] vector)
           
 MatrixBuilder translate(double[] from, double[] to)
           
 MatrixBuilder translate(double dx, double dy, double dz)
           
 MatrixBuilder translateFromTo(double[] p1, double[] p2)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

euclidean

public static MatrixBuilder euclidean(Transformation m)
Create a matrix builder which generates isometries with respect to euclidean metric.

Parameters:
m -
Returns:

euclidean

public static MatrixBuilder euclidean(Matrix m)

euclidean

public static MatrixBuilder euclidean()
Create a matrix builder which generates isometries with respect to euclidean metric.

Parameters:
m -
Returns:

euclidean

public static MatrixBuilder euclidean(SceneGraphComponent cmp)

hyperbolic

public static MatrixBuilder hyperbolic(Transformation m)

hyperbolic

public static MatrixBuilder hyperbolic(Matrix m)

hyperbolic

public static MatrixBuilder hyperbolic()
Create a matrix builder which generates isometries with respect to hyperbolic (or (3,1)) metric.

Parameters:
m -
Returns:

hyperbolic

public static MatrixBuilder hyperbolic(SceneGraphComponent cmp)

elliptic

public static MatrixBuilder elliptic(Transformation m)

elliptic

public static MatrixBuilder elliptic(Matrix m)

elliptic

public static MatrixBuilder elliptic()
Create a matrix builder which generates isometries with respect to elliptic (or (4,0)) metric.

Parameters:
m -
Returns:

elliptic

public static MatrixBuilder elliptic(SceneGraphComponent cmp)

projective

public static MatrixBuilder projective(Transformation m)

projective

public static MatrixBuilder projective(Matrix m)

projective

public static MatrixBuilder projective()
Create a matrix builder which strictly speaking doesn't know about metric: purely projective. Results of using the isometry methods on this instance are undefined.

Parameters:
m -
Returns:

init

public static MatrixBuilder init(Matrix m,
                                 int metric)
This constructor accepts the metric as an argument. It's often convenient to be able to specify the metric in this way rather than searching for the specific metric-specific method.


rotate

public MatrixBuilder rotate(double angle,
                            double axisX,
                            double axisY,
                            double axisZ)

rotate

public MatrixBuilder rotate(double angle,
                            double[] axis)

rotate

public MatrixBuilder rotate(double[] p1,
                            double[] p2,
                            double angle)
rotate about the axis through the points p1 and p2

Parameters:
p1 - first point on axis
p2 - second point on axis
angle - the angle to rotate
Returns:
a MatrixBuilder...
See Also:
P3.makeRotationMatrix(double[], double[], double[], double, int)

rotateX

public MatrixBuilder rotateX(double angle)

rotateY

public MatrixBuilder rotateY(double angle)

rotateZ

public MatrixBuilder rotateZ(double angle)

rotateFromTo

public MatrixBuilder rotateFromTo(double[] v1,
                                  double[] v2)
A rotation which takes vector v1 to vector v2. These vectors do not need to be normalized.

Parameters:
v1 -
v2 -
Returns:
See Also:
P3.makeRotationMatrix(double[], double[], double[])

scale

public MatrixBuilder scale(double scale)
Parameters:
scale -
Returns:
See Also:
P3.makeStretchMatrix(double[], double)

scale

public MatrixBuilder scale(double[] scale)
Parameters:
scale -
Returns:
See Also:
P3.makeStretchMatrix(double[], double[])

scale

public MatrixBuilder scale(double scaleX,
                           double scaleY,
                           double scaleZ)
Parameters:
scaleX -
scaleY -
scaleZ -
Returns:
See Also:
P3.makeStretchMatrix(double[], double, double, double)

skew

public MatrixBuilder skew(int i,
                          int j,
                          double val)

translate

public MatrixBuilder translate(double[] vector)

translate

public MatrixBuilder translate(double[] from,
                               double[] to)

translate

public MatrixBuilder translate(double dx,
                               double dy,
                               double dz)
Parameters:
dx -
dy -
dz -
Returns:
See Also:
P3.makeTranslationMatrix(double[], double[], int)

translateFromTo

public MatrixBuilder translateFromTo(double[] p1,
                                     double[] p2)
Parameters:
p1 -
p2 -
Returns:
See Also:
P3.makeTranslationMatrix(double[], double[], double[], int)

reflect

public MatrixBuilder reflect(double[] v1,
                             double[] v2,
                             double[] v3)
reflects the wrapped Matrix at the plane determined by the the given 3 points

Parameters:
v1 - first point on reflection plane
v2 - second point on reflection plane
v3 - third point on reflection plane
Returns:
this

reflect

public MatrixBuilder reflect(double[] plane)
reflects the wrapped Matrix at the plane

Parameters:
plane -
Returns:
this
See Also:
P3.makeReflectionMatrix(double[], double[], int)

conjugateBy

public MatrixBuilder conjugateBy(double[] c)

times

public MatrixBuilder times(Matrix matrix)
multiplies the given Matrix on the right hand side

Parameters:
matrix -
Returns:
this

times

public MatrixBuilder times(double[] array)
multiplies array (considered as 4x4 matrix) on the right hand side

Parameters:
array -
Returns:
this

reset

public MatrixBuilder reset()
assigns ID to the underlying matrix

Returns:

getMatrix

public Matrix getMatrix()

assignTo

public void assignTo(SceneGraphComponent comp)

assignTo

public void assignTo(Transformation trafo)

assignTo

public void assignTo(double[] array)

assignTo

public void assignTo(Matrix m)

getArray

public double[] getArray()