Class Matrix
- java.lang.Object
-
- gov.nasa.worldwind.geom.Matrix
-
public class Matrix extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description protected static double
EPSILON
static Matrix
IDENTITY
double
m11
double
m12
double
m13
double
m14
double
m21
double
m22
double
m23
double
m24
double
m31
double
m32
double
m33
double
m34
double
m41
double
m42
double
m43
double
m44
protected static double
NEAR_ZERO_THRESHOLD
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Matrix
add(Matrix matrix)
static void
computeEigensystemFromSymmetricMatrix3(Matrix matrix, double[] outEigenvalues, Vec4[] outEigenvectors)
Computes the eigensystem of the specified symmetric Matrix's upper 3x3 matrix.Matrix
divideComponents(double value)
Matrix
divideComponents(Matrix matrix)
boolean
equals(java.lang.Object obj)
Vec4
extractEyePoint()
Extracts this viewing matrix's eye point.Vec4
extractForwardVector()
Extracts this viewing matrix's forward vector.AVList
extractViewingParameters(Vec4 origin, Angle roll, Globe globe)
Extracts this viewing matrix's parameters given a viewing origin and a globe.static Matrix
fromArray(double[] compArray, int offset, boolean rowMajor)
static Matrix
fromAxes(Vec4[] axes)
Returns a Cartesian transformMatrix
that maps a local orientation to model coordinates.static Matrix
fromAxisAngle(Angle angle, double axisX, double axisY, double axisZ)
static Matrix
fromAxisAngle(Angle angle, Vec4 axis)
static Matrix
fromCovarianceOfVertices(BufferWrapper coordinates, int stride)
Computes a symmetric covariance Matrix from the x, y, z coordinates of the specified buffer of points.static Matrix
fromCovarianceOfVertices(java.lang.Iterable<? extends Vec4> points)
Computes a symmetric covariance Matrix from the x, y, z coordinates of the specified points Iterable.static Matrix
fromGeographicToImage(AVList worldFileParams)
static Matrix
fromGeographicToImage(java.awt.geom.Point2D[] imagePoints, LatLon[] geoPoints)
static Matrix
fromGeographicToViewport(Sector sector, int x, int y, int width, int height)
Computes a Matrix that will map the geographic region defined by sector onto a Cartesian region of the specifiedwidth
andheight
and centered at the point(x, y)
.static Matrix
fromImageToGeographic(int imageWidth, int imageHeight, Sector sector)
Computes aMatrix
that will map a aligned 2D grid coordinates to geographic coordinates in degrees.static Matrix
fromImageToGeographic(AVList worldFileParams)
static Matrix
fromImageToGeographic(java.awt.geom.Point2D[] imagePoints, LatLon[] geoPoints)
Computes aMatrix
that will map constrained 2D grid coordinates to geographic coordinates in degrees.static Matrix
fromLocalOrientation(Vec4 origin, Vec4[] axes)
Returns a Cartesian transformMatrix
that maps a local origin and orientation to model coordinates.static Matrix
fromModelLookAt(Vec4 eye, Vec4 center, Vec4 up)
Returns a local origin transform matrix in model coordinates defined by the specified eye point, reference point indicating the center of the local scene, and up vector.static Matrix
fromOrthographic(double width, double height, double near, double far)
static Matrix
fromOrthographic2D(double width, double height)
static Matrix
fromPerspective(double width, double height, double near, double far)
static Matrix
fromPerspective(Angle horizontalFieldOfView, double viewportWidth, double viewportHeight, double near, double far)
static Matrix
fromQuaternion(Quaternion quaternion)
static Matrix
fromRotationX(Angle angle)
static Matrix
fromRotationXYZ(Angle xRotation, Angle yRotation, Angle zRotation)
static Matrix
fromRotationY(Angle angle)
static Matrix
fromRotationZ(Angle angle)
static Matrix
fromScale(double scale)
static Matrix
fromScale(double scaleX, double scaleY, double scaleZ)
static Matrix
fromScale(Vec4 scale)
static Matrix
fromSkew(Angle theta, Angle phi)
static Matrix
fromTranslation(double x, double y, double z)
static Matrix
fromTranslation(Vec4 translation)
static Matrix
fromViewLookAt(Vec4 eye, Vec4 center, Vec4 up)
Returns a viewing matrix in model coordinates defined by the specified View eye point, reference point indicating the center of the scene, and up vector.static Matrix
fromViewportToGeographic(Sector sector, int x, int y, int width, int height)
Computes a Matrix that will map a Cartesian region of the specifiedwidth
andheight
and centered at the point(x, y)
to the geographic region defined by sector onto .double
getDeterminant()
Matrix
getInverse()
Returns the inverse of this matrix, ornull
if this matrix is singular and has no inverse.Angle
getKMLRotationX()
Angle
getKMLRotationY()
Angle
getKMLRotationZ()
double
getM11()
double
getM12()
double
getM13()
double
getM14()
double
getM21()
double
getM22()
double
getM23()
double
getM24()
double
getM31()
double
getM32()
double
getM33()
double
getM34()
double
getM41()
double
getM42()
double
getM43()
double
getM44()
Angle
getRotationX()
Angle
getRotationY()
Angle
getRotationZ()
double
getTrace()
Vec4
getTranslation()
Matrix
getTranspose()
int
hashCode()
double
m11()
double
m12()
double
m13()
double
m14()
double
m21()
double
m22()
double
m23()
double
m24()
double
m31()
double
m32()
double
m33()
double
m34()
double
m41()
double
m42()
double
m43()
double
m44()
Matrix
multiply(Matrix matrix)
Matrix
multiplyComponents(double value)
Matrix
negate()
Matrix
subtract(Matrix matrix)
double[]
toArray(double[] compArray, int offset, boolean rowMajor)
java.lang.String
toString()
Vec4
transformBy3(Matrix matrix, double x, double y, double z)
-
-
-
Field Detail
-
IDENTITY
public static final Matrix IDENTITY
-
m11
public final double m11
-
m12
public final double m12
-
m13
public final double m13
-
m14
public final double m14
-
m21
public final double m21
-
m22
public final double m22
-
m23
public final double m23
-
m24
public final double m24
-
m31
public final double m31
-
m32
public final double m32
-
m33
public final double m33
-
m34
public final double m34
-
m41
public final double m41
-
m42
public final double m42
-
m43
public final double m43
-
m44
public final double m44
-
EPSILON
protected static final double EPSILON
- See Also:
- Constant Field Values
-
NEAR_ZERO_THRESHOLD
protected static final double NEAR_ZERO_THRESHOLD
- See Also:
- Constant Field Values
-
-
Method Detail
-
equals
public final boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public final int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
fromArray
public static Matrix fromArray(double[] compArray, int offset, boolean rowMajor)
-
toArray
public final double[] toArray(double[] compArray, int offset, boolean rowMajor)
-
toString
public final java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getM11
public final double getM11()
-
getM12
public final double getM12()
-
getM13
public final double getM13()
-
getM14
public final double getM14()
-
getM21
public final double getM21()
-
getM22
public final double getM22()
-
getM23
public final double getM23()
-
getM24
public final double getM24()
-
getM31
public final double getM31()
-
getM32
public final double getM32()
-
getM33
public final double getM33()
-
getM34
public final double getM34()
-
getM41
public final double getM41()
-
getM42
public final double getM42()
-
getM43
public final double getM43()
-
getM44
public final double getM44()
-
m11
public final double m11()
-
m12
public final double m12()
-
m13
public final double m13()
-
m14
public final double m14()
-
m21
public final double m21()
-
m22
public final double m22()
-
m23
public final double m23()
-
m24
public final double m24()
-
m31
public final double m31()
-
m32
public final double m32()
-
m33
public final double m33()
-
m34
public final double m34()
-
m41
public final double m41()
-
m42
public final double m42()
-
m43
public final double m43()
-
m44
public final double m44()
-
fromAxes
public static Matrix fromAxes(Vec4[] axes)
Returns a Cartesian transformMatrix
that maps a local orientation to model coordinates. The orientation is specified by an array of threeaxes
. Theaxes
array must contain three non-null vectors, which are interpreted in the following order: x-axis, y-axis, z-axis. This ensures that the axes in the returnedMatrix
have unit length and are orthogonal to each other.- Parameters:
axes
- an array must of three non-null vectors defining a local orientation in the following order: x-axis, y-axis, z-axis.- Returns:
- a
Matrix
that a transforms local coordinates to world coordinates. - Throws:
java.lang.IllegalArgumentException
- ifaxes
isnull
, ifaxes
contains less than three elements, or if any of the first three elements inaxes
isnull
.
-
fromAxisAngle
public static Matrix fromAxisAngle(Angle angle, double axisX, double axisY, double axisZ)
-
fromQuaternion
public static Matrix fromQuaternion(Quaternion quaternion)
-
fromRotationXYZ
public static Matrix fromRotationXYZ(Angle xRotation, Angle yRotation, Angle zRotation)
-
fromScale
public static Matrix fromScale(double scale)
-
fromScale
public static Matrix fromScale(double scaleX, double scaleY, double scaleZ)
-
fromTranslation
public static Matrix fromTranslation(double x, double y, double z)
-
fromLocalOrientation
public static Matrix fromLocalOrientation(Vec4 origin, Vec4[] axes)
Returns a Cartesian transformMatrix
that maps a local origin and orientation to model coordinates. The transform is specified by a localorigin
and an array of threeaxes
. Theaxes
array must contain three non-null vectors, which are interpreted in the following order: x-axis, y-axis, z-axis. This ensures that the axes in the returnedMatrix
have unit length and are orthogonal to each other.- Parameters:
origin
- the origin of the local coordinate system.axes
- an array must of three non-null vectors defining a local orientation in the following order: x-axis, y-axis, z-axis.- Returns:
- a
Matrix
that transforms local coordinates to world coordinates. - Throws:
java.lang.IllegalArgumentException
- iforigin
isnull
, ifaxes
isnull
, ifaxes
contains less than three elements, or if any of the first three elements inaxes
isnull
.
-
fromViewLookAt
public static Matrix fromViewLookAt(Vec4 eye, Vec4 center, Vec4 up)
Returns a viewing matrix in model coordinates defined by the specified View eye point, reference point indicating the center of the scene, and up vector. The eye point, center point, and up vector are in model coordinates. The returned viewing matrix maps the reference center point to the negative Z axis, and the eye point to the origin, and the up vector to the positive Y axis. When this matrix is used to define an OGL viewing transform along with a typical projection matrix such asfromPerspective(Angle, double, double, double, double)
, this maps the center of the scene to the center of the viewport, and maps the up vector to the viewoport's positive Y axis (the up vector points up in the viewport). The eye point and reference center point must not be coincident, and the up vector must not be parallel to the line of sight (the vector from the eye point to the reference center point).- Parameters:
eye
- the eye point, in model coordinates.center
- the scene's reference center point, in model coordinates.up
- the direction of the up vector, in model coordinates.- Returns:
- a viewing matrix in model coordinates defined by the specified eye point, reference center point, and up vector.
- Throws:
java.lang.IllegalArgumentException
- if any of the eye point, reference center point, or up vector are null, if the eye point and reference center point are coincident, or if the up vector and the line of sight are parallel.
-
fromModelLookAt
public static Matrix fromModelLookAt(Vec4 eye, Vec4 center, Vec4 up)
Returns a local origin transform matrix in model coordinates defined by the specified eye point, reference point indicating the center of the local scene, and up vector. The eye point, center point, and up vector are in model coordinates. The returned viewing matrix maps the the positive Z axis to the reference center point, the origin to the eye point, and the positive Y axis to the up vector. The eye point and reference center point must not be coincident, and the up vector must not be parallel to the line of sight (the vector from the eye point to the reference center point).- Parameters:
eye
- the eye point, in model coordinates.center
- the scene's reference center point, in model coordinates.up
- the direction of the up vector, in model coordinates.- Returns:
- a viewing matrix in model coordinates defined by the specified eye point, reference center point, and up vector.
- Throws:
java.lang.IllegalArgumentException
- if any of the eye point, reference center point, or up vector are null, if the eye point and reference center point are coincident, or if the up vector and the line of sight are parallel.
-
fromPerspective
public static Matrix fromPerspective(Angle horizontalFieldOfView, double viewportWidth, double viewportHeight, double near, double far)
-
fromPerspective
public static Matrix fromPerspective(double width, double height, double near, double far)
-
fromOrthographic
public static Matrix fromOrthographic(double width, double height, double near, double far)
-
fromOrthographic2D
public static Matrix fromOrthographic2D(double width, double height)
-
fromImageToGeographic
public static Matrix fromImageToGeographic(int imageWidth, int imageHeight, Sector sector)
Computes aMatrix
that will map a aligned 2D grid coordinates to geographic coordinates in degrees. It is assumed that the destination grid is parallel with lines of latitude and longitude, and has its origin in the upper left hand corner.- Parameters:
sector
- the grid sector.imageWidth
- the grid width.imageHeight
- the grid height.- Returns:
Matrix
that will map from grid coordinates to geographic coordinates in degrees.- Throws:
java.lang.IllegalArgumentException
- ifsector
is null, or if eitherwidth
orheight
are less than 1.
-
fromImageToGeographic
public static Matrix fromImageToGeographic(java.awt.geom.Point2D[] imagePoints, LatLon[] geoPoints)
Computes aMatrix
that will map constrained 2D grid coordinates to geographic coordinates in degrees. The grid is defined by three control points. Each control point maps a location in the source grid to a geographic location.- Parameters:
imagePoints
- three control points in the source grid.geoPoints
- three geographic locations corresponding to each grid control point.- Returns:
Matrix
that will map from geographic coordinates to grid coordinates in degrees.- Throws:
java.lang.IllegalArgumentException
- if eitherimagePoints
orgeoPoints
is null or have length less than 3.
-
fromGeographicToImage
public static Matrix fromGeographicToImage(java.awt.geom.Point2D[] imagePoints, LatLon[] geoPoints)
-
fromGeographicToViewport
public static Matrix fromGeographicToViewport(Sector sector, int x, int y, int width, int height)
Computes a Matrix that will map the geographic region defined by sector onto a Cartesian region of the specifiedwidth
andheight
and centered at the point(x, y)
.- Parameters:
sector
- the geographic region which will be mapped to the Cartesian regionx
- x-coordinate of lower left hand corner of the Cartesian regiony
- y-coordinate of lower left hand corner of the Cartesian regionwidth
- width of the Cartesian region, extending to the right from the x-coordinateheight
- height of the Cartesian region, extending up from the y-coordinate- Returns:
- Matrix that will map from the geographic region to the Cartesian region.
- Throws:
java.lang.IllegalArgumentException
- ifsector
is null, or ifwidth
orheight
are less than zero.
-
fromViewportToGeographic
public static Matrix fromViewportToGeographic(Sector sector, int x, int y, int width, int height)
Computes a Matrix that will map a Cartesian region of the specifiedwidth
andheight
and centered at the point(x, y)
to the geographic region defined by sector onto .- Parameters:
sector
- the geographic region the Cartesian region will be mapped tox
- x-coordinate of lower left hand corner of the Cartesian regiony
- y-coordinate of lower left hand corner of the Cartesian regionwidth
- width of the Cartesian region, extending to the right from the x-coordinateheight
- height of the Cartesian region, extending up from the y-coordinate- Returns:
- Matrix that will map from Cartesian region to the geographic region.
- Throws:
java.lang.IllegalArgumentException
- ifsector
is null, or ifwidth
orheight
are less than zero.
-
fromCovarianceOfVertices
public static Matrix fromCovarianceOfVertices(java.lang.Iterable<? extends Vec4> points)
Computes a symmetric covariance Matrix from the x, y, z coordinates of the specified points Iterable. This returns null if the points Iterable is empty, or if all of the points are null.The returned covariance matrix represents the correlation between each pair of x-, y-, and z-coordinates as they're distributed about the point Iterable's arithmetic mean. Its layout is as follows:
C(x, x) C(x, y) C(x, z)
C(x, y) C(y, y) C(y, z)
C(x, z) C(y, z) C(z, z)C(i, j) is the covariance of coordinates i and j, where i or j are a coordinate's dispersion about its mean value. If any entry is zero, then there's no correlation between the two coordinates defining that entry. If the returned matrix is diagonal, then all three coordinates are uncorrelated, and the specified point Iterable is distributed evenly about its mean point.
- Parameters:
points
- the Iterable of points for which to compute a Covariance matrix.- Returns:
- the covariance matrix for the iterable of 3D points.
- Throws:
java.lang.IllegalArgumentException
- if the points Iterable is null.
-
fromCovarianceOfVertices
public static Matrix fromCovarianceOfVertices(BufferWrapper coordinates, int stride)
Computes a symmetric covariance Matrix from the x, y, z coordinates of the specified buffer of points. This returns null if the buffer is empty.The returned covariance matrix represents the correlation between each pair of x-, y-, and z-coordinates as they're distributed about the points arithmetic mean. Its layout is as follows:
C(x, x) C(x, y) C(x, z)
C(x, y) C(y, y) C(y, z)
C(x, z) C(y, z) C(z, z)C(i, j) is the covariance of coordinates i and j, where i or j are a coordinate's dispersion about its mean value. If any entry is zero, then there's no correlation between the two coordinates defining that entry. If the returned matrix is diagonal, then all three coordinates are uncorrelated, and the specified points are distributed evenly about their mean point.
The buffer must contain XYZ coordinate tuples which are either tightly packed or offset by the specified stride. The stride specifies the number of buffer elements between the first coordinate of consecutive tuples. For example, a stride of 3 specifies that each tuple is tightly packed as XYZXYZXYZ, whereas a stride of 5 specifies that there are two elements between each tuple as XYZabXYZab (the elements "a" and "b" are ignored). The stride must be at least 3. If the buffer's length is not evenly divisible into stride-sized tuples, this ignores the remaining elements that follow the last complete tuple.
- Parameters:
coordinates
- the buffer containing the point coordinates for which to compute a Covariance matrix.stride
- the number of elements between the first coordinate of consecutive points. If stride is 3, this interprets the buffer has having tightly packed XYZ coordinate tuples.- Returns:
- the covariance matrix for the buffer of points.
- Throws:
java.lang.IllegalArgumentException
- if the buffer is null, or if the stride is less than three.
-
computeEigensystemFromSymmetricMatrix3
public static void computeEigensystemFromSymmetricMatrix3(Matrix matrix, double[] outEigenvalues, Vec4[] outEigenvectors)
Computes the eigensystem of the specified symmetric Matrix's upper 3x3 matrix. If the Matrix's upper 3x3 matrix is not symmetric, this throws an IllegalArgumentException. This writes the eigensystem parameters to the specified arraysoutEigenValues
andoutEigenVectors
, placing the eigenvalues in the entries of arrayoutEigenValues
, and the corresponding eigenvectors in the entires of arrayoutEigenVectors
. These arrays must be non-null, and have length three or greater.- Parameters:
matrix
- the symmetric Matrix for which to compute an eigensystem.outEigenvalues
- the array which receives the three output eigenvalues.outEigenvectors
- the array which receives the three output eigenvectors.- Throws:
java.lang.IllegalArgumentException
- if the Matrix is null or is not symmetric, if the output eigenvalue array is null or has length less than 3, or if the output eigenvector is null or has length less than 3.
-
multiplyComponents
public final Matrix multiplyComponents(double value)
-
divideComponents
public final Matrix divideComponents(double value)
-
negate
public final Matrix negate()
-
getDeterminant
public final double getDeterminant()
-
getTranspose
public final Matrix getTranspose()
-
getTrace
public final double getTrace()
-
getInverse
public final Matrix getInverse()
Returns the inverse of this matrix, ornull
if this matrix is singular and has no inverse.- Returns:
- the inverse of this matrix, or
null
if this matrix has no inverse.
-
getRotationX
public final Angle getRotationX()
-
getRotationY
public final Angle getRotationY()
-
getRotationZ
public final Angle getRotationZ()
-
getKMLRotationX
public final Angle getKMLRotationX()
-
getKMLRotationY
public final Angle getKMLRotationY()
-
getKMLRotationZ
public final Angle getKMLRotationZ()
-
getTranslation
public final Vec4 getTranslation()
-
extractEyePoint
public Vec4 extractEyePoint()
Extracts this viewing matrix's eye point.This method assumes that this matrix represents a viewing matrix. If this does not represent a viewing matrix the results are undefined.
In model coordinates, a viewing matrix's eye point is the point the viewer is looking from and maps to the center of the screen.
- Returns:
- this viewing matrix's eye point, in model coordinates.
-
extractForwardVector
public Vec4 extractForwardVector()
Extracts this viewing matrix's forward vector.This method assumes that this matrix represents a viewing matrix. If this does not represent a viewing matrix the results are undefined.
In model coordinates, a viewing matrix's forward vector is the direction the viewer is looking and maps to a vector going into the screen.
- Returns:
- this viewing matrix's forward vector, in model coordinates.
-
extractViewingParameters
public AVList extractViewingParameters(Vec4 origin, Angle roll, Globe globe)
Extracts this viewing matrix's parameters given a viewing origin and a globe.This method assumes that this matrix represents a viewing matrix. If this does not represent a viewing matrix the results are undefined.
This returns a parameterization of this viewing matrix based on the specified origin and globe. The origin indicates the model coordinate point that the view's orientation is relative to, while the globe provides the necessary model coordinate context for the origin and the orientation. The origin should be either the view's eye point or a point on the view's forward vector. The view's roll must be specified in order to disambiguate heading and roll when the view's tilt is zero. The following list outlines the returned key-value pairs and their meanings:
- AVKey.ORIGIN - The geographic position corresponding to the origin point.
- AVKey.RANGE - The distance between the specified origin point and the view's eye point, in model coordinates.
- AVKey.HEADING - The view's heading angle relative to the globe's north pointing tangent at the origin point.
- AVKey.TILT - The view's tilt angle relative to the globe's normal vector at the origin point.
- AVKey.ROLL - The view's roll relative to the globe's normal vector at the origin point.
- Parameters:
origin
- the origin of the viewing parameters, in model coordinates.roll
- the view's roll.globe
- the globe the viewer is looking at.- Returns:
- a parameterization of this viewing matrix as a list of key-value pairs.
- Throws:
java.lang.IllegalArgumentException
- if any argument is null.
-
-