/*****************************************************************************\
 * MathOps
\*****************************************************************************/

package com.mhuss.AstroLib;

/**
 * MathOps contains some useful trig, vector and matrix operations.
 * 

* Based on C code by Bill Gray (www.projectpluto.com) */ public class MathOps { // Change to public by Strickling /** * Calculates the arc cosine, but limits the input to the range * ( -1.0 < rad < +1.0 ).
* This avoids overflow errors. If the input is <= -1.0 radians, * Math.PI is returned. If the input is >= 1.0 radians, * 0 is returned. * * @param arg The angle in radians * * @return The arc cosine, limited to the range 0 to Pi. */ public static double acose( double arg ) { if( arg >= 1D ) return( 0D ); else if( arg <= -1D ) return( Math.PI ); else return( Math.acos( arg ) ); } /** * Calculates the arc sine, but limits the input to the range * ( -1.0 < rad < +1.0 ).
* This avoids overflow errors. If the input is less than * -1 (radian), -PI/2 is returned. If the input is greater than * 1 (radian), +PI/2 is returned. * * @param arg The angle in radians * * @return The arc sine, limited to the range -Pi/2 0 to Pi/2. */ public static double asine( double arg ) { if( arg >= 1. ) return( Astro.PI_OVER_TWO ); else if( arg <= -1. ) return( -Astro.PI_OVER_TWO ); else return( Math.asin( arg) ); } // typedef double AstroVector[3]; public static final int VECTOR_SIZE = 3; //typedef double AstroMatrix[9]; static final int MATRIX_SIZE = 9; /** * Initializes a matrix to base (identity) values. * The matrix is set as follows: * [1][0][0] * [0][1][0] * [0][0][1] * * * @param matrix The matrix to initialize */ public static void setIdentityMatrix( double matrix[] ) { for( int i=0; i * Inverting an orthonormal matrix is simple: * swap rows and columns, and you're done. */ static void invertOrthonormalMatrix( double matrix[] ) { double temp; // swap [1] and [3] temp = matrix[1]; matrix[1] = matrix[3]; matrix[3] = temp; // swap [2] and [6] temp = matrix[2]; matrix[2] = matrix[6]; matrix[6] = temp; // swap [5] and [7] temp = matrix[5]; matrix[5] = matrix[7]; matrix[7] = temp; } /** * Prespin matrices. * * @param m1 The first matrix * @param m2 The second matrix * @param angle The angle to use */ static void preSpinMatrix( double m1[], double m2[], double angle ) { double sinAng = Math.sin( angle ); double cosAng = Math.cos( angle ); double tval; for( int i=0; i

Ads help maintain this website.