de.jreality.math

## Class P3

• ```public class P3
extends Object```
Static methods for geometry of real projective 3-space (RP3). As with `Pn`, some methods are purely projective, while others relate to the various metric geometries contained within projective geometry.

The bulk of the methods here fall into three categories:

• Methods to generate isometries of a particular 3-dimensional metric geometry,
• Methods related to perspective transformations in 3D rendering, and
• Methods related to line (Pluecker) coordinates of lines in RP3.

Only methods which are specific to 3-dimensional space are included here. Actually most of the methods of the first sort listed above could be generalized and moved to `Pn`. Any volunteers?

Scaling transformations are included here even though scaling is not an isometry in any metric. `Rn` for method conventions and representation of matrices. `Pn` for other methods applicable in n-dimensional real projective space.

Author:
Charles Gunn
• ### Field Summary

Fields
Modifier and Type Field and Description
`static double[]` `originP3`
`static double[]` `p3involution`
`static double[]` `Q_ELLIPTIC`
`static double[]` `Q_EUCLIDEAN`
`static double[]` `Q_HYPERBOLIC`
`static double[][]` `Q_LIST`
• ### Method Summary

All Methods
Modifier and Type Method and Description
`static double` ```affineCoordinate(double[] p1, double[] p2, double[] pw)```
`static boolean` ```areCollinear(double[] p0, double[] p1, double[] p2, double tol)```
`static double[]` ```barycentricCoordinates(double[] weights, double[] p0, double[] p1, double[] p)```
`static double[]` ```composeMatrixFromFactors(double[] m, double[] transV, Quaternion rotQ, Quaternion stretchRotQ, double[] stretchV, boolean isFlipped, int metric)```
`static double[]` ```extractOrientationMatrix(double[] dst, double[] src, double[] point, int metric)```
Extract a matrix from the src input matrix, such that it fixes the input position point.
`static double[]` ```factorMatrix(double[] m, double[] transV, Quaternion rotQ, Quaternion stretchRotQ, double[] stretchV, boolean[] isFlipped, int metric)```
see Graphics Gems IV, p.
`static double[]` ```getTransformedAbsolute(double[] m, int metric)```
`static boolean` ```isometryIsUnstable(double[] matrix, int metric)```
`static boolean` ```isValidTranslationVector(double[] vec, int metric)```
`static double[]` ```lineIntersectPlane(double[] dst, double[] p1, double[] p2, double[] plane)```
Calculate the intersection point of the line determined by p1 and p2 with plane.
`static double[]` ```lineJoinPoint(double[] plane, double[] p1, double[] p2, double[] point)```
`static double[]` ```makeDirectIsometryFromFrames(double[] dst, double[] p0, double[] p1, double[] p2, double[] q0, double[] q1, double[] q2, int metric)```
Generate a direct isometry that carries the frame determined by p0, p1 and p2 to that determined by q0, q1 and q2.
`static double[]` ```makeGlideReflectionMatrix(double[] m, double[] p1, double[] p2, double[] plane, int metric)```
Generate a glide reflection in plane with translation vector given by the vector from p1 to p2.
`static double[]` ```makeLookatMatrix(double[] m, double[] from, double[] to, double roll, int metric)```
Creates an isometry that carries the from vector to the origin; and takes the normalized to vector to the (homogeneous) vector (0,0,-1,0).
`static double[]` ```makeOrthographicProjectionMatrix(double[] m, Rectangle2D viewport, double near, double far)```
`static double[]` ```makePerspectiveProjectionMatrix(double[] dst, Rectangle2D viewport, double near, double far)```
Generate a 4x4 perspective projection matrix based on the parameters.
`static float[]` ```makePerspectiveProjectionMatrix(float[] dst, Rectangle2D viewport, float near, float far)```
`static double[]` ```makeReflectionMatrix(double[] m, double[] plane, int metric)```
Construct a projective reflection that fixes the element plane considered as a pole/polar point/plane pair.
`static double[]` ```makeRotationMatrix(double[] m, double[] axis, double angle)```
Generate a rotation matrix fixing the origin (0,0,0,1) around the given axis with the given angle.
`static double[]` ```makeRotationMatrix(double[] m, double[] from, double[] to)```
Generate a rotation matrix which fixes the origin (0,0,0,1) and carries the vector from to the vector to.
`static double[]` ```makeRotationMatrix(double[] m, double[] p1, double[] p2, double angle, int metric)```
Calculate a rotation matrix in the given metric which rotates a given angle about the axis determined by p1 and p2.
`static double[]` ```makeRotationMatrixX(double[] mat, double angle)```
`static double[]` ```makeRotationMatrixY(double[] mat, double angle)```
`static double[]` ```makeRotationMatrixZ(double[] mat, double angle)```
`static double[]` ```makeScaleMatrix(double[] dst, double s)```
For those who are uncomfortable with the word stretch -- even though only euclidean geometry supports scaling (changing size without changing shape).
`static double[]` ```makeScaleMatrix(double[] dst, double[] s)```
`static double[]` ```makeScaleMatrix(double[] dst, double sx, double sy, double sz)```
`static double[]` ```makeScrewMotionMatrix(double[] dst, double[] p1, double[] p2, double angle, int metric)```
`static double[]` ```makeSkewMatrix(double[] dst, int i, int j, double val)```
`static double[]` ```makeStretchMatrix(double[] dst, double stretch)```
Create a diagonal matric with entries (stretch, stretch,stretch, 1)
`static double[]` ```makeStretchMatrix(double[] dst, double[] v)```
Construct a diagonal matrix with the given entries.
`static double[]` ```makeStretchMatrix(double[] dst, double xscale, double yscale, double zscale)```
Create a diagonal matric with entries (xscale, yscale, zscale, 1)
`static double[]` ```makeTranslationMatrix(double[] dst, double[] from, double[] to, int metric)```
Calculate a translation matrix in the given metric which carries the point from to the point to and maps the line joining from and to to itself (the axis of the isometry).
`static double[]` ```makeTranslationMatrix(double[] mat, double[] to, int metric)```
Calculate a translation matrix which carries the origin (0,0,0,1 to the point to.
`static double` ```orientation(double[] to, double[] up, double[] upNoRoll)```
Calculate the determinant of the matrix spanned by the three input vectors and the origin (0,0,0,1).
`static double[]` ```orthonormalizeMatrix(double[] dst, double[] m, double tolerance, int metric)```
Attempt to convert a matrix m into an isometry with respect to metric metric.
`static double[]` ```perpendicularBisector(double[] dst, double[] p1, double[] p2, int metric)```
Calculate the plane coordinates for the plane which lies midway between the input planes p1 and p2.
`static double[]` ```planeFromPoints(double[] planeIn, double[] p1, double[] p2, double[] p3)```
Construct the homogeneous plane coordinates for the plane containing the three points (p1, p2, p3).
`static double[]` ```pointFromPlanes(double[] point, double[] p1, double[] p2, double[] p3)```
• ### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Field Detail

• #### p3involution

`public static double[] p3involution`
• #### Q_HYPERBOLIC

`public static double[] Q_HYPERBOLIC`
• #### Q_EUCLIDEAN

`public static double[] Q_EUCLIDEAN`
• #### Q_ELLIPTIC

`public static double[] Q_ELLIPTIC`
• #### Q_LIST

`public static double[][] Q_LIST`
• #### originP3

`public static double[] originP3`
• ### Method Detail

• #### composeMatrixFromFactors

```public static double[] composeMatrixFromFactors(double[] m,
double[] transV,
Quaternion rotQ,
Quaternion stretchRotQ,
double[] stretchV,
boolean isFlipped,
int metric)```
Parameters:
`m` -
`transV` -
`rotQ` -
`stretchRotQ` -
`stretchV` -
`isFlipped` -
`metric` -
Returns:
• #### makePerspectiveProjectionMatrix

```public static float[] makePerspectiveProjectionMatrix(float[] dst,
Rectangle2D viewport,
float near,
float far)```
• #### extractOrientationMatrix

```public static double[] extractOrientationMatrix(double[] dst,
double[] src,
double[] point,
int metric)```
Extract a matrix from the src input matrix, such that it fixes the input position point. (simple: it looks at the image of point and translates it back)
Parameters:
`dst` -
`src` -
`point` -
`metric` -
Returns:
• #### factorMatrix

```public static double[] factorMatrix(double[] m,
double[] transV,
Quaternion rotQ,
Quaternion stretchRotQ,
double[] stretchV,
boolean[] isFlipped,
int metric)```
see Graphics Gems IV, p. 207 for details "polar matrix decomposition" yields a factorization of the form A = TRFUSU' where T translation F flip (x[i] -> -x[i], i=0,1,2) R rotation U "stretch rotation" S scale U' U transpose Additional argument for composeMatrixFromFactors centerV center of rotation Currently U is assumed to be the identity, and metric must be EUCLIDEAN.
Parameters:
`m` -
`transV` -
`rotQ` -
`stretchRotQ` -
`stretchV` -
`isFlipped` -
`metric` -
Returns:
• #### makeGlideReflectionMatrix

```public static double[] makeGlideReflectionMatrix(double[] m,
double[] p1,
double[] p2,
double[] plane,
int metric)```
Generate a glide reflection in plane with translation vector given by the vector from p1 to p2. Both these points must lie in the plane. Under construction.
Parameters:
`m` -
`vec` -
Returns:
not referenced
• #### makeLookatMatrix

```public static double[] makeLookatMatrix(double[] m,
double[] from,
double[] to,
double roll,
int metric)```
Creates an isometry that carries the from vector to the origin; and takes the normalized to vector to the (homogeneous) vector (0,0,-1,0). The orthogonal complement of these two vectors is rotated by roll degrees. This transformation represents the worldToCamera transformation for a camera whose position in world coordinates is the point from and which is pointed to look in the direction of to.
Parameters:
`m` -
`from` -
`to` -
`roll` -
`metric` -
Returns:
• #### makeOrthographicProjectionMatrix

```public static double[] makeOrthographicProjectionMatrix(double[] m,
Rectangle2D viewport,
double near,
double far)```
Parameters:
`m` -
`viewport` -
`n` -
`f` -
Returns:
• #### makePerspectiveProjectionMatrix

```public static double[] makePerspectiveProjectionMatrix(double[] dst,
Rectangle2D viewport,
double near,
double far)```
Generate a 4x4 perspective projection matrix based on the parameters.
Parameters:
`dst` - matrix to put the result
`viewport` - The viewport of the camera (normalized to lie in z = -1 plane)
`n` - near clipping plane
`f` - far clipping plane
Returns:
• #### makeReflectionMatrix

```public static double[] makeReflectionMatrix(double[] m,
double[] plane,
int metric)```
Construct a projective reflection that fixes the element plane considered as a pole/polar point/plane pair. That is, the fixed elements of the transformation are the point vec and the polar plane Q.vec where Q is the diagonal matrix representing the absolute quadric of the given metric. Such a transformation is also known as a harmonic involution. Warning Under construction!
Parameters:
`m` -
`vec` -
`metric` -
Returns:
• #### makeRotationMatrix

```public static double[] makeRotationMatrix(double[] m,
double[] axis,
double angle)```
Generate a rotation matrix fixing the origin (0,0,0,1) around the given axis with the given angle. The matrix is a 4x4 matrix, which differs from the identity matrix only in the upper 3x3 corner.
Parameters:
`m` - the target matrix
`axis` - double
`angle` -
Returns:
• #### makeRotationMatrix

```public static double[] makeRotationMatrix(double[] m,
double[] from,
double[] to)```
Generate a rotation matrix which fixes the origin (0,0,0,1) and carries the vector from to the vector to. The output matrix is 4x4. from and to are 3-vectors.
Parameters:
`m` - double
`from` - double
`to` - double
Returns:
• #### makeRotationMatrix

```public static double[] makeRotationMatrix(double[] m,
double[] p1,
double[] p2,
double angle,
int metric)```
Calculate a rotation matrix in the given metric which rotates a given angle about the axis determined by p1 and p2.
Parameters:
`m` -
`p1` -
`p2` -
`angle` -
`metric` -
Returns:
• #### makeRotationMatrixX

```public static double[] makeRotationMatrixX(double[] mat,
double angle)```
Parameters:
`object` -
`earthPhi` -
Returns:
• #### makeRotationMatrixY

```public static double[] makeRotationMatrixY(double[] mat,
double angle)```
• #### makeRotationMatrixZ

```public static double[] makeRotationMatrixZ(double[] mat,
double angle)```
• #### makeStretchMatrix

```public static double[] makeStretchMatrix(double[] dst,
double stretch)```
Create a diagonal matric with entries (stretch, stretch,stretch, 1)
Parameters:
`dst` -
`stretch` -
Returns:
• #### makeStretchMatrix

```public static double[] makeStretchMatrix(double[] dst,
double xscale,
double yscale,
double zscale)```
Create a diagonal matric with entries (xscale, yscale, zscale, 1)
Parameters:
`dst` -
`xscale` -
`yscale` -
`zscale` -
Returns:
• #### makeStretchMatrix

```public static double[] makeStretchMatrix(double[] dst,
double[] v)```
Construct a diagonal matrix with the given entries. The length of v can be arbitrary.
Parameters:
`dst` -
`scales` -
Returns:
dst
• #### makeScaleMatrix

```public static double[] makeScaleMatrix(double[] dst,
double s)```
For those who are uncomfortable with the word stretch -- even though only euclidean geometry supports scaling (changing size without changing shape).
Parameters:
`dst` -
`s` -
Returns:
• #### makeScaleMatrix

```public static double[] makeScaleMatrix(double[] dst,
double[] s)```
• #### makeScaleMatrix

```public static double[] makeScaleMatrix(double[] dst,
double sx,
double sy,
double sz)```
• #### makeSkewMatrix

```public static double[] makeSkewMatrix(double[] dst,
int i,
int j,
double val)```
• #### makeScrewMotionMatrix

```public static double[] makeScrewMotionMatrix(double[] dst,
double[] p1,
double[] p2,
double angle,
int metric)```
• #### makeTranslationMatrix

```public static double[] makeTranslationMatrix(double[] dst,
double[] from,
double[] to,
int metric)```
Calculate a translation matrix in the given metric which carries the point from to the point to and maps the line joining from and to to itself (the axis of the isometry).
Parameters:
`dst` -
`from` -
`to` -
`metric` -
Returns:
• #### makeTranslationMatrix

```public static double[] makeTranslationMatrix(double[] mat,
double[] to,
int metric)```
Calculate a translation matrix which carries the origin (0,0,0,1 to the point to.
Parameters:
`mat` -
`to` -
`metric` -
Returns:
• #### isValidTranslationVector

```public static boolean isValidTranslationVector(double[] vec,
int metric)```
• #### makeDirectIsometryFromFrames

```public static double[] makeDirectIsometryFromFrames(double[] dst,
double[] p0,
double[] p1,
double[] p2,
double[] q0,
double[] q1,
double[] q2,
int metric)```
Generate a direct isometry that carries the frame determined by p0, p1 and p2 to that determined by q0, q1 and q2. See `#makeDirectIsometryFromFrame(double[], double[], double[], int)`.
Parameters:
`dst` -
`p0` -
`p1` -
`q0` -
`q1` -
`metric` -
Returns:
• #### orientation

```public static double orientation(double[] to,
double[] up,
double[] upNoRoll)```
Calculate the determinant of the matrix spanned by the three input vectors and the origin (0,0,0,1).
Parameters:
`to` -
`up` -
`upNoRoll` -
Returns:
• #### orthonormalizeMatrix

```public static double[] orthonormalizeMatrix(double[] dst,
double[] m,
double tolerance,
int metric)```
Attempt to convert a matrix m into an isometry with respect to metric metric. This is useful if round-off errors have accumulated through a continuous sequence of motions.
Parameters:
`dst` -
`m` -
`tolerance` -
`metric` -
Returns:
• #### getTransformedAbsolute

```public static double[] getTransformedAbsolute(double[] m,
int metric)```
• #### isometryIsUnstable

```public static boolean isometryIsUnstable(double[] matrix,
int metric)```
• #### perpendicularBisector

```public static double[] perpendicularBisector(double[] dst,
double[] p1,
double[] p2,
int metric)```
Calculate the plane coordinates for the plane which lies midway between the input planes p1 and p2. Midway in this case means the distances (with respect to metric) of dst to the two inputs are equal. There are generally two such planes when the measure on the plane pencil spanned by the two inputs is elliptic; we try to choose the one closer to both of the planes.
Parameters:
`dst` -
`p1` -
`p2` -
`metric` -
Returns:
• #### planeFromPoints

```public static double[] planeFromPoints(double[] planeIn,
double[] p1,
double[] p2,
double[] p3)```
Construct the homogeneous plane coordinates for the plane containing the three points (p1, p2, p3). The method does not check for degenerate conditions.
Parameters:
`plane` - double
`p1` - double or double
`p2` - double or double
`p3` - double or double
Returns:
plane
• #### lineIntersectPlane

```public static double[] lineIntersectPlane(double[] dst,
double[] p1,
double[] p2,
double[] plane)```
Calculate the intersection point of the line determined by p1 and p2 with plane.
Parameters:
`point` -
`p1` -
`p2` -
`plane` -
Returns:
The intersection point
• #### pointFromPlanes

```public static double[] pointFromPlanes(double[] point,
double[] p1,
double[] p2,
double[] p3)```
Parameters:
`point` -
`p1` -
`p2` -
`p3` -
Returns:
• #### lineJoinPoint

```public static double[] lineJoinPoint(double[] plane,
double[] p1,
double[] p2,
double[] point)```
• #### areCollinear

```public static boolean areCollinear(double[] p0,
double[] p1,
double[] p2,
double tol)```
• #### barycentricCoordinates

```public static double[] barycentricCoordinates(double[] weights,
double[] p0,
double[] p1,
double[] p)```
• #### affineCoordinate

```public static double affineCoordinate(double[] p1,
double[] p2,
double[] pw)```