• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by moghes · Jun 22, 2012 at 08:03 AM · distancemathspherecalculatearc

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Owen-Reynolds · Jun 22, 2012 at 02:14 PM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image moghes · Jun 22, 2012 at 04:36 PM 0
Share

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

avatar image
1

Answer by MV10 · Jan 02, 2016 at 06:44 AM

Wolfram-Alpha defines great-circle spherical distance as the arcosine of the dot product of the two coordinates:


   float SphericalDistance(Vector3 position1, Vector3 position2)
    {
        return Mathf.Acos(Vector3.Dot(position1, position2));
    }

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jasbro · Jul 17, 2016 at 05:13 AM 0
Share

Wolfram's explanation is for a unit sphere. In most applications, radius must be considered. This makes sense. As the radius approaches infinity, the distance between P1 and P2 will almost become a straight line. But if the radius was exactly half the straight line distance between P1 and P2, then the distance would equal pi*radius.

avatar image Bunny83 jasbro · Jul 17, 2016 at 01:45 PM 0
Share

This approach is correct, you just need to multiply by the radius at the end. Also position1 and position2 need to be normalized, otherwise acos won't return there right angle.

avatar image
0

Answer by zaghaghi · Jun 22, 2012 at 02:57 PM

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

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RyanShackelford · May 04, 2018 at 10:45 PM 0
Share

If I read the vector formula correctly, the following code should calculate the orthodromic distance accurately.

 float CalculateSurfaceDistance(Vector3 point1, Vector3 point2){
         return $$anonymous$$athf.Atan((Vector3.$$anonymous$$agnitude((Vector3.Cross(point1,point2))))/(Vector3.Dot(point1, point2)));
     }


Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Vector3.distance wrong distance calculating? 2 Answers

Need to place an object at a certain angle form the camera and at a certaine distance 0 Answers

Calculate time to destination taking account current speed, also how to determine distance between two objects? 1 Answer

How to draw an arc on a sphere??? 0 Answers

How to detect when an object is within an arc? 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges