开发者

Find 2 points on a 3d object and get their distance

Ok. So I guess thing would to be envision new york city and beijing highlighted on google earth...

I'm trying to figure out how to map points onto a 3d primitive object (a sphere), get their distance via any direction by the circumference, and their distance by diameter. The points are going to be 开发者_StackOverflowlatitude and longitude coordinates.

Right now, this is what i'm trying to use to map the coordinates (a code agnostic version):

  x1 =  radius * cos(long1) * cos(lat1);
  y1 =  radius * sin(long1) * cos(lat1);
  z1 =  radius * sin(lat1);

but i'm almost sure its wrong. How could I get each points position and calculate their distances straight across the sphere's diameter and also their distance going around the circumference of the sphere?

Thanks.


You're actually pretty close. To get the straight line distance, you simply need to do:

sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2)

For the distance around the great circle, remember that it is pidiamangle. The dot product of the vectors from the center of the earth to the two points is the cosine of the angle. So, you get:

pidiamacos((x1*x2 + y1*y2 + z1*z1)/diam^2)

of course there's a 2nd distance if you go the other way around the earth, but for that you just need 2*pi - acos(...).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜