开发者

Problems using the acos function in J2ME in eclipse

"I'm working with J2ME in eclipse, and need to use the method aco开发者_Go百科s() belongs to the Math package, the question is that the package available for J2ME Math is not that function (limitations of mobiles), then I want an algorithm or method alternative to calculate the cosine.

I need the "acos" to calculate the following formula:

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);

This function allows me from two geographical coordinates to calculate the distance in kilometers between them. If there is an alternative method to calculate this distance (where the cosine is not used), I also would be useful.

Any help on this?


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);
}


You could try to implement the arccosine as shown here.


If you have the Location API available you can use the distance method from the Coordinates class. From the Coordinates API:

public float distance(Coordinates to)

Calculates the geodetic distance between the two points according to the ellipsoid model of WGS84. Altitude is neglected from calculations. The implementation shall calculate this as exactly as it can. However, it is required that the result is within 0.35% of the correct result.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜