Using trigonometric functions in the look-up table of j2ec-based Systems

Source: Internet
Author: User
Tags in degrees


Both CLDC and MIDP do not provide trigonometric functions, and CLDC1.0 does not have floating point numbers. Therefore, we choose to look up tables. Use the sin and cos tables with 8-Bit fixed points. The following is the code in wtk's own demo. It only provides a limited number of angles. You can refine the angle values as needed.
// Sines of angles 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, all x 256
Private static final int [] SINES =
{0, 44, 88,128,165,196,222,241,252,256 };
// Angle is in degrees/10, I. e. 0 .. 36 for full circle
Private static int sineTimes256 (int angle)
{
Angle % = 36; // 360 degrees
If (angle <= 9) // 0 .. 90 degrees
{
Return SINES [angle];
}
Else if (angle <= 18) // 90 .. 180 degrees
{
Return SINES [18-angle];
}
Else if (angle <= 27) // 180 .. 270 degrees
{
Return-SINES [angle-18];
}
Else // 270 .. 360 degrees
{
Return-SINES [36-angle];
}
}
// Angle is in degrees/10, I. e. 0 .. 36 for full circle
Private static int cosineTimes256 (int angle)
{
Return sineTimes256 (angle + 9); // I. e. add 90 degrees
}

Related Article

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.