最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
J2ME中查表法使用三角函数
时间:2008-01-12 编辑:简简单单 来源:一聚教程网
CLDC和MIDP都没有提供三角函数,而且CLDC1.0中也没有浮点数,所以我们的选择是查表。使用8位定点数的sin和cos表。下面是wtk自带demo中的代码,只提供了有限的几个角度,实际使用时根据需要细化角度值。
// sines of angles 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, all *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
}
-
上一个: J2ME学习笔记(三)
-
下一个: J2ME学习(三)――如何播放声音
相关文章
- wps使用函数的方法 07-04
- Python递归函数定义与用法 06-05
- 如何学会创建并调用函数 05-18
- golang 函数中函数和方法有什么区别 05-13
- python socket函数中,send与sendall有什么区别 怎么使用 05-11
- wps表格中怎么使用函数 使用方法 04-17