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
}