Module JNISpice
Package spice.basic

Class Matrix33


  • public class Matrix33
    extends java.lang.Object
    Class Matrix33 represents 3 by 3 double precision matrices.

    Version 1.0.0 22-DEC-2009 (NJB)

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private double[][] m  
    • Constructor Summary

      Constructors 
      Constructor Description
      Matrix33()
      No-arguments constructor: create a zero-filled 3x3 matrix.
      Matrix33​(double[] array)
      Construct a Matrix33 from an array of type double[].
      Matrix33​(double[][] array3x3)
      Construct a Matrix33 from an array of type double[][].
      Matrix33​(int axisIndex, double angle)
      Construct a rotation matrix that transforms vectors from the standard basis to a basis rotated about a specified coordinate axis by a specified angle.
      Matrix33​(Matrix33 matrix)
      Construct a Matrix33 from another Matrix33.This method creates a deep copy.
      Matrix33​(Vector3 axis, double angle)
      Construct a rotation matrix that rotates vectors about a specified axis vector by a specified angle.
      Matrix33​(Vector3 primaryVector, int primaryIndex, Vector3 secondaryVector, int secondaryIndex)
      Construct a rotation matrix representing a reference frame defined by primary and secondary vectors.A specified axis of the frame is aligned with the primary vector; another specified axis is aligned with the component of the secondary vector that is orthogonal to the primary vector.
      Matrix33​(Vector3 row0, Vector3 row1, Vector3 row2)
      Construct a Matrix33 from a set of three row vectors.Each row is represented by a Vector3.
    • Method Summary

      Modifier and Type Method Description
      Matrix33 add​(Matrix33 m2)
      Add this instance to another Matrix33 instance.
      private Matrix33 createMatrix33​(double[][] array3x3)
      Private utility to construct a Matrix33 from an array of type double[][].
      double det()
      Return the determinant of this instance.
      double dist​(Matrix33 m2)
      Return the vector (L2) distance between this instance and another Matrix33 instance.
      static Matrix33 fill​(double value)
      Fill all elements of a matrix with a given constant.
      double getElt​(int i, int j)
      Return the element of this instance at index [i][j].
      static Matrix33 identity()
      Return the identity matrix.
      Matrix33 invert()
      Invert this instance.
      boolean isRotation​(double normTol, double determinantTol)
      Indicate whether this instance is a rotation matrix.
      Matrix33 mtxm​(Matrix33 m2)
      Multiply a Matrix33 instance on the left by the transpose of this instance.
      Vector3 mtxv​(Vector3 vin)
      Multiply a vector on the left by the transpose of this instance.
      Matrix33 mxm​(Matrix33 m2)
      Multiply another Matrix33 instance on the left by this instance.
      Matrix33 mxmt​(Matrix33 m2)
      Multiply the transpose of a Matrix33 instance on the left by this instance.
      Vector3 mxv​(Vector3 vin)
      Multiply a Vector3 on the left by this instance.
      double norm()
      Compute the vector (L2) norm of this instance.
      Matrix33 scale​(double s)
      Multiply this instance by a scalar.
      Matrix33 sub​(Matrix33 m2)
      Subtract another Matrix33 instance from this instance.
      double[][] toArray()
      Return a 3x3 array containing the contents of this Matrix33 instance.
      double[] toArray1D()
      Return a 1-dimensional array containing the contents of this Matrix33 instance.
      java.lang.String toString()
      Convert this instance to a String.This method overrides Object's toString() method.
      Matrix33 xpose()
      Transpose this instance.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • m

        private double[][] m
    • Constructor Detail

      • Matrix33

        public Matrix33()
        No-arguments constructor: create a zero-filled 3x3 matrix.
      • Matrix33

        public Matrix33​(Matrix33 matrix)
        Construct a Matrix33 from another Matrix33.This method creates a deep copy.
        Parameters:
        matrix - Matrix33
      • Matrix33

        public Matrix33​(double[][] array3x3)
                 throws SpiceException
        Construct a Matrix33 from an array of type double[][].
        Parameters:
        array3x3 - double[][]
        Throws:
        SpiceException - exception
      • Matrix33

        public Matrix33​(double[] array)
                 throws SpiceException
        Construct a Matrix33 from an array of type double[].

        The array is considered to consist of rows 0-2 of the matrix, in that order.

        Parameters:
        array - double[]
        Throws:
        SpiceException - exception
      • Matrix33

        public Matrix33​(Vector3 row0,
                        Vector3 row1,
                        Vector3 row2)
        Construct a Matrix33 from a set of three row vectors.Each row is represented by a Vector3.
        Parameters:
        row0 - Vector3
        row2 - Vector3
        row1 - Vector3
      • Matrix33

        public Matrix33​(Vector3 primaryVector,
                        int primaryIndex,
                        Vector3 secondaryVector,
                        int secondaryIndex)
                 throws SpiceException
        Construct a rotation matrix representing a reference frame defined by primary and secondary vectors.A specified axis of the frame is aligned with the primary vector; another specified axis is aligned with the component of the secondary vector that is orthogonal to the primary vector.

        This constructor is analogous to the twovec_c function of CSPICE.

        The association of axes and axis numbers is as follows:

              axis     index
              ----     -----
               X         1
               Y         2
               Z         3
           

        The matrix created by this constructor transforms vectors from the standard basis to that defined by the input vectors.

        Example

        The numerical results shown for this example may differ across platforms. The results depend on the compiler and supporting libraries, and the machine specific arithmetic implementation.

        Create a matrix that transforms vectors from the standard basis to one whose X-axis is aligned with the vector (1,1,1) and whose Z-axis is aligned with the component of (0,0,1) that is orthogonal to its X-axis.

              import spice.basic.*;
        
              class Twovec
              {
                 //
                 // Load the JNISpice shared library.
                 //
                 static { System.loadLibrary( "JNISpice" ); }
        
        
                 public static void main ( String[] args )
                 {
                    try
                    {
                       Vector3  primary   = new Vector3( 1, 1, 1 );
                       Vector3  secondary = new Vector3( 0, 0, 1 );
        
                       Matrix33 r         = new Matrix33( primary, 1, secondary, 3 );
        
                       System.out.println ( r );
        
                    }
                    catch ( SpiceException exc ) {
                       exc.printStackTrace();
                    }
                 }
              }
           

        When run on a PC/Linux/java 1.6.0_14/gcc platform, the output from this program was (lines below were wrapped to fit into the 80 character page width):

                5.7735026918962580e-01,   5.7735026918962580e-01,   5.773502691896258
        0e-01,
               -7.0710678118654750e-01,   7.0710678118654750e-01,   0.000000000000000
        0e+00,
               -4.0824829046386310e-01,  -4.0824829046386310e-01,   8.164965809277261
        0e-01
           
        Parameters:
        primaryVector - Vector3
        secondaryIndex - int
        primaryIndex - int
        secondaryVector - Vector3
        Throws:
        SpiceException - exception
      • Matrix33

        public Matrix33​(int axisIndex,
                        double angle)
                 throws SpiceException
        Construct a rotation matrix that transforms vectors from the standard basis to a basis rotated about a specified coordinate axis by a specified angle.

        This constructor is analogous to the rotate_c function of CSPICE.

        The association of axes and axis numbers is as follows:

              axis     index
              ----     -----
               X         1
               Y         2
               Z         3
           

        The angle is expressed in radians.

        Parameters:
        axisIndex - int
        angle - double
        Throws:
        SpiceException - exception
      • Matrix33

        public Matrix33​(Vector3 axis,
                        double angle)
                 throws SpiceException
        Construct a rotation matrix that rotates vectors about a specified axis vector by a specified angle.

        This constructor is analogous to the axisar_c function of CSPICE.

        The angle is expressed in radians.

        Parameters:
        axis - Vector3
        angle - double
        Throws:
        SpiceException - exception
    • Method Detail

      • createMatrix33

        private Matrix33 createMatrix33​(double[][] array3x3)
        Private utility to construct a Matrix33 from an array of type double[][]. Caution: this utility does no error checking.
      • add

        public Matrix33 add​(Matrix33 m2)
        Add this instance to another Matrix33 instance.
        Parameters:
        m2 - Matrix33
        Returns:
        Matrix33
      • det

        public double det()
                   throws SpiceException
        Return the determinant of this instance.
        Returns:
        double
        Throws:
        SpiceException - exception
      • dist

        public double dist​(Matrix33 m2)
        Return the vector (L2) distance between this instance and another Matrix33 instance.
        Parameters:
        m2 - Matrix33
        Returns:
        double
      • fill

        public static Matrix33 fill​(double value)
        Fill all elements of a matrix with a given constant.
        Parameters:
        value - double
        Returns:
        Matrix33
      • getElt

        public double getElt​(int i,
                             int j)
                      throws SpiceException
        Return the element of this instance at index [i][j].
        Parameters:
        i - int
        j - int
        Returns:
        double
        Throws:
        SpiceException - exception
      • identity

        public static Matrix33 identity()
        Return the identity matrix.
        Returns:
        Matrix33
      • isRotation

        public boolean isRotation​(double normTol,
                                  double determinantTol)
                           throws SpiceException
        Indicate whether this instance is a rotation matrix.

        The input tolerance values are used, respectively, as the maximum deviation of the magnitude of the matrix's columns from 1 and of the matrix's determinant from 1.

        Parameters:
        normTol - double
        determinantTol - double
        Returns:
        boolean
        Throws:
        SpiceException - exception
      • mxm

        public Matrix33 mxm​(Matrix33 m2)
        Multiply another Matrix33 instance on the left by this instance.
        Parameters:
        m2 - Matrix33
        Returns:
        Matrix33
      • mtxm

        public Matrix33 mtxm​(Matrix33 m2)
        Multiply a Matrix33 instance on the left by the transpose of this instance.
        Parameters:
        m2 - Matrix33
        Returns:
        Matrix33
      • mtxv

        public Vector3 mtxv​(Vector3 vin)
        Multiply a vector on the left by the transpose of this instance.
        Parameters:
        vin - Vector3
        Returns:
        Vector3
      • mxmt

        public Matrix33 mxmt​(Matrix33 m2)
        Multiply the transpose of a Matrix33 instance on the left by this instance.
        Parameters:
        m2 - Matrix33
        Returns:
        Matrix33
      • mxv

        public Vector3 mxv​(Vector3 vin)
        Multiply a Vector3 on the left by this instance.
        Parameters:
        vin - Vector3
        Returns:
        Vector3
      • norm

        public double norm()
        Compute the vector (L2) norm of this instance.
        Returns:
        double
      • sub

        public Matrix33 sub​(Matrix33 m2)
        Subtract another Matrix33 instance from this instance.
        Parameters:
        m2 - Matrix33
        Returns:
        Matrix33
      • scale

        public Matrix33 scale​(double s)
        Multiply this instance by a scalar.
        Parameters:
        s - double
        Returns:
        Matrix33
      • toArray

        public double[][] toArray()
        Return a 3x3 array containing the contents of this Matrix33 instance.
        Returns:
        double[][]
      • toArray1D

        public double[] toArray1D()
        Return a 1-dimensional array containing the contents of this Matrix33 instance.
        Returns:
        double[]
      • toString

        public java.lang.String toString()
        Convert this instance to a String.This method overrides Object's toString() method.
        Overrides:
        toString in class java.lang.Object
        Returns:
        String
      • xpose

        public Matrix33 xpose()
        Transpose this instance.
        Returns:
        Matrix33