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
}