“我在 eclipse 中使用 J2ME,需要使用方法 acos()
属于 Math 包,问题是该包可用于J2ME Math 不是那个函数(手机的限制),那么我想要一个算法或方法来计算余弦。
我需要“acos”来计算以下公式:
long2 = cood[i].getLongitud();
lat2 = cood[i].getLatitud();
dlong = (long1 - long2);
c = dlong * degtorad;
dvalue = (Math.sin(a) * Math.sin(b))+(Math.cos(a) * Math.cos(b)*Math.cos(c));
dd = Math.acos(dvalue) * radtodeg;
km = (dd * 111.302);
此函数允许我根据两个地理坐标来计算它们之间的距离(以公里为单位)。如果有另一种方法来计算这个距离(不使用余弦的地方),我也会很有用。
有什么帮助吗?
最佳答案
public static double acos(double a)
{
final double epsilon=1.0E-7;
double x=a;
do {
x-=(Math.sin(x)-a)/Math.cos(x);
}
while (Math.abs(Math.sin(x)-a)>epsilon);
// returned angle is in radians
return -1*(x-Math.PI/2);
}
关于java - 在eclipse中使用J2ME中acos函数的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7339454/