private double ACos( double d ) { // we probably need to consider tolerance here. if( Math.Abs( d ) != 1.0 ) { return ( 1.5707963267949 - Math.Atan( d / Math.Sqrt( 1.0 - d * d ) ) ); } if( d == -1.0 ) { return 3.14159265358979; } return 0.0; }