Class Matrix


  • public class Matrix
    extends java.lang.Object
    • 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
    • Constructor Detail

      • Matrix

        public Matrix​(double value)
      • Matrix

        public Matrix​(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)
    • Method Detail

      • equals

        public final boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public final int hashCode()
        Overrides:
        hashCode in class java.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 class java.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 transform Matrix that maps a local orientation to model coordinates. The orientation is specified by an array of three axes. The axes 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 returned Matrix 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 - if axes is null, if axes contains less than three elements, or if any of the first three elements in axes is null.
      • fromAxisAngle

        public static Matrix fromAxisAngle​(Angle angle,
                                           Vec4 axis)
      • 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)
      • fromRotationX

        public static Matrix fromRotationX​(Angle angle)
      • fromRotationY

        public static Matrix fromRotationY​(Angle angle)
      • fromRotationZ

        public static Matrix fromRotationZ​(Angle angle)
      • fromScale

        public static Matrix fromScale​(double scale)
      • fromScale

        public static Matrix fromScale​(Vec4 scale)
      • fromScale

        public static Matrix fromScale​(double scaleX,
                                       double scaleY,
                                       double scaleZ)
      • fromTranslation

        public static Matrix fromTranslation​(Vec4 translation)
      • fromTranslation

        public static Matrix fromTranslation​(double x,
                                             double y,
                                             double z)
      • fromLocalOrientation

        public static Matrix fromLocalOrientation​(Vec4 origin,
                                                  Vec4[] axes)
        Returns a Cartesian transform Matrix that maps a local origin and orientation to model coordinates. The transform is specified by a local origin and an array of three axes. The axes 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 returned Matrix 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 - if origin is null, if axes is null, if axes contains less than three elements, or if any of the first three elements in axes is null.
      • 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 as fromPerspective(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 a Matrix 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 - if sector is null, or if either width or height are less than 1.
      • fromImageToGeographic

        public static Matrix fromImageToGeographic​(AVList worldFileParams)
      • fromGeographicToImage

        public static Matrix fromGeographicToImage​(AVList worldFileParams)
      • fromImageToGeographic

        public static Matrix fromImageToGeographic​(java.awt.geom.Point2D[] imagePoints,
                                                   LatLon[] geoPoints)
        Computes a Matrix 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 either imagePoints or geoPoints 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 specified width and height and centered at the point (x, y).
        Parameters:
        sector - the geographic region which will be mapped to the Cartesian region
        x - x-coordinate of lower left hand corner of the Cartesian region
        y - y-coordinate of lower left hand corner of the Cartesian region
        width - width of the Cartesian region, extending to the right from the x-coordinate
        height - 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 - if sector is null, or if width or height 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 specified width and height 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 to
        x - x-coordinate of lower left hand corner of the Cartesian region
        y - y-coordinate of lower left hand corner of the Cartesian region
        width - width of the Cartesian region, extending to the right from the x-coordinate
        height - 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 - if sector is null, or if width or height 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 arrays outEigenValues and outEigenVectors, placing the eigenvalues in the entries of array outEigenValues, and the corresponding eigenvectors in the entires of array outEigenVectors. 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.
      • subtract

        public final Matrix subtract​(Matrix matrix)
      • multiplyComponents

        public final Matrix multiplyComponents​(double value)
      • multiply

        public final Matrix multiply​(Matrix matrix)
      • divideComponents

        public final Matrix divideComponents​(double value)
      • divideComponents

        public final Matrix divideComponents​(Matrix matrix)
      • negate

        public final Matrix negate()
      • transformBy3

        public final Vec4 transformBy3​(Matrix matrix,
                                       double x,
                                       double y,
                                       double z)
      • 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, or null 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.