Fast Trigonometry functions for x86. - Java java.lang

Java examples for java.lang:Math Function

Description

Fast Trigonometry functions for x86.

Demo Code


//package com.java2s;

public class Main {
    /**/*from  www .  j  a va  2  s.co m*/
     * Fast Trigonometry functions for x86.  
     * This forces the trigonometry functions to stay within the safe area on the x86 processor (-45 degrees to +45 degrees)
     * The results may be very slightly off from what the Math and StrictMath trigonometry functions give due to
     * rounding in the angle reduction but it will be very very close.
     * 
     * @param radians The original angle
     * @return The reduced Sin angle
     * @author JeffK
     */
    private static double reduceSinAngle(double radians) {
        radians %= Math.PI * 2.0; // put us in -2PI to +2PI space

        if (Math.abs(radians) > Math.PI) { // put us in -PI to +PI space
            radians = radians - (Math.PI * 2.0);
        }
        if (Math.abs(radians) > Math.PI / 2) {// put us in -PI/2 to +PI/2 space
            radians = Math.PI - radians;
        }

        return radians;
    }
}

Related Tutorials