Some unimplemented trigonometric functions in J2EE

Source: Internet
Author: User
I did not expect so many limitations on the calculation of latitude and longitude in the J2EE today. Even a few simple trigonometric functions are not completely provided, and I need to write them directly. no way. Do it yourself. leave a code for reference later. package COM. ken. math;

/***//**
* Returns arc tangent, arcsin, and arccosine using the formula. <br>
* Tan (x) = sin (X)/cos (x) <br>
* Arcsin (x) = arctan (x/SQRT (1-sqr (X) <br>
* Arccos (x) = arctan (SQRT (1-sqr (x)/x) <br>
*
* @ Author <a href = "mailto: xzknet@gmail.com"> ken_xu </a>
* @ Version 1.0 copyright 04:09:04
*/
Public class supermath ...{
/***//**
* Arc tangent <br>
* Radian is the tangent. The value range of this function is-π/2 ~ π/2
*
* @ Param radian
* Degrees in radians
* @ Return returns the arc tangent corresponding to the angle
* @ Author ken_xu
*/
Public static double acttan (double radian )...{
System. Out. println (radian );
Double retval = 0d;
If (math. Abs (radian) <= 1.0d )...{
Retval = radian/(1.0d + 0.28d * sqr (radian ));
} Else ...{
Retval =-radian/(sqr (radian) + 0.28d );
If (radian <-1.0d )...{
Retval = retval-math. PI/2;
} Else ...{
Retval = retval + math. PI/2;
}
}
Return retval;
}

/***//**
* Arc tangent <br>
* The tangent value is Y/X. Therefore, this function calculates the angle corresponding to Y/X. The value of this function is-π ~ π
*
* @ Param y
* @ Param x
* @ Return returns the arc tangent corresponding to the angle
* @ Author ken_xu
*/
Public static double acttan (Double Y, double X )...{
If (y = 0.0d & X = 0.0d)
Return 0.0d;
If (x> 0.0d)
Return acttan (y/X );
If (x <0.0f)
If (Y <0.0d)
Return (-(math. Pi-acttan (y/X )));
Else
Return (math. Pi-acttan (-y/X ));
Return y> = 0.0f? Math. PI/2: Math. PI/2;
}

/***//**
* ARC sine
*
* @ Param radian
* Degrees in radians
* @ Return the arcsin corresponding to the angle
* @ Author ken_xu
*/
Public static double actsin (double radian )...{
// Arcsin (x) = arctan (x/SQRT (1-sqr (X )))
Double retval = acttan (radian/Math. SQRT (1-sqr (radian )));
Return retval;
}

/***//**
* Arccosine
*
* @ Param radian
* Degrees in radians
* @ Return returns the arc cosine of the angle.
* @ Author ken_xu
*/
Public static double actcos (double radian )...{
// Arccos (x) = arctan (SQRT (1-sqr (x)/X)
Double retval = acttan (math. SQRT (1-sqr (radian)/radian );
Return retval;
}

/***//**
* Square Functions
*
* @ Param x
* @ Return square value (x * X)
* @ Author ken_xu
*/
Public static double sqr (Double X )...{
Return x * X;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.