x


Calculate the arc distance between 2 points on a sphere

Hello Everyone, I have an issue here, its related to math but some hints are appretiated. The player has to position 3d models on a sphere which is the globe. For example a building.. and after plotting I have to display the distance between his poltted position and the accurate position. I am getting the player chosen point by a raycast, so on mouse down the model will be plotted and I save have the hit point and the other point is defined by me. I have positioned small sphere's at the accurate position, so the position of these sphere's have to be compared to the hit point(position) to get the distance(arc distance) I think to get the arc distance I need a third point which is the center of the sphere(globe) and hence I can get the radus, since the hit point and the original position is the on surface of the globe. I really appretiate any help!

more ▼

asked Jun 22 '12 at 08:03 AM

moghes gravatar image

moghes
660 17 30 44

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Using the center point sounds right. Run a "spoke" from the center to one point; find the angle to the other; you know 360 degrees is a distance of 2xPIxR; find the percent. Untested:

Vector3 spokeToActual = playerPos-sphereCenter,
        spokeToCorrect = correctPos-sphereCenter;
float angleFromCenter = Vector3.Angle(spokeToActual, spokeToCorrect);
// NOTE: angle inputs don't need normalize. In degrees(!!)

float D = 2*Mathf.PI*radius * (angleFromCenter/360);

As a check, print that along with playerPos-correctPos).magnitude. It should only be a little bit bigger, if the player is remotely close.

more ▼

answered Jun 22 '12 at 02:14 PM

Owen Reynolds gravatar image

Owen Reynolds
11.5k 1 7 45

sounds to be the solutoins, i'll try this out then comment! thanks alot btw

Jun 22 '12 at 04:36 PM moghes
(comments are locked)
10|3000 characters needed characters left

Hi, I think that you need to compute great circle distance:

http://en.wikipedia.org/wiki/Great-circle_distance

more ▼

answered Jun 22 '12 at 02:57 PM

zaghaghi gravatar image

zaghaghi
0

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x355
x212
x199
x35
x25

asked: Jun 22 '12 at 08:03 AM

Seen: 674 times

Last Updated: Jun 22 '12 at 04:36 PM