开发者

what is happening in following code [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 9 years ago.

Improve this question

Could any one tell me what is happening in following code? I'm trying to work through a tutorial and I'm getting a bit lost.

I'm not sure how the following function could be called, or how to set the parameters (e.g. if brng =45 and dist=1.

LatLon.prototype.destinationPoint = function(brng, dist) {

    dist = typeof(dist)=='number' ? dist : typeof(dist)=='string' && dist.trim()!='' ? +dist :  NaN;

    dist = dist/this._radius;  // convert dist to angular distance in radians

    brng = brng.toRad();  // 

    var lat1 = th开发者_开发技巧is._lat.toRad(), lon1 = this._lon.toRad();

    var lat2 = Math.asin( Math.sin(lat1)*Math.cos(dist) + 
                            Math.cos(lat1)*Math.sin(dist)*Math.cos(brng) );

    var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(dist)*Math.cos(lat1),  
                                   Math.cos(dist)-Math.sin(lat1)*Math.sin(lat2));

    lon2 = (lon2+3*Math.PI)%(2*Math.PI) - Math.PI;  // normalise to -180...+180

    return new LatLon(lat2.toDeg(), lon2.toDeg());

}

This code can be found at following page http://www.movable-type.co.uk/scripts/latlong.html


don't know if you ever before coded JS but you have to create a function which will represent you class...

function LatLon(lat, lon, rad) {

if you wrote this you can invoke this "constructor" by typing

var myLatLon = new LatLon(lat, lon, rad)

plus the same from before!


You can call it this way

var myLatLon = new LatLon();
maLatLon.destinationPoint(45, 1);

have you read this!?

http://en.wikipedia.org/wiki/Great_circle

do you want to know what each line does or do want to know whats the purpose of the calculation is ?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜