Whenever you click on a spinning globe, the intersections are shown in world coordinates. This means that if you repeatedly click on the same spot while the globe is rotating, you will likely get the same intersection point each time.
However, it's essential to note that these hit points are determined by the sphere's geometry. Therefore, a low-poly sphere may not return a position that corresponds perfectly to a lat/lon position as expected with a flawless sphere.
To achieve more accurate results, there are a few additional steps you can take:
1. Establish a Sphere Representation
Create a mathematically perfect representation of your globe using a Sphere
.
2. Utilize Ray for Intersections
The Raycaster
tool is handy for setting up raycasting effortlessly. You can also use Raycaster.ray
(Ray
) for manual steps.
For instance, apply Ray.intersectSphere
on your perfect sphere to determine the precise intersection point.
3. Convert to Local Coordinates
The reason you were consistently hitting the same point is that the intersection was in world coordinates. To convert to local coordinates, use Object3D.worldToLocal
to convert the global hit point into a local one (note that this method changes the Vector3
).
4. Determine Latitude and Longitude
Select a point on your globe representing the intersection of the equator and prime meridian (0, 0). If north is +Y, your origin could be defined as
new Vector3( 0, 0, sphere.radius )
.
When calculating longitude, eliminate the Y component from the hit vector (hit.y = 0
), set its length to the sphere radius (hit.setLength( sphere.radius )
), then utilize Vector3.angleTo
to find and convert the angle to degrees. The X component signifies the East/West part of your value.
As for latitude, create a copy of the hit vector minus the Y component. Adjust its length to the sphere's radius and calculate the angle between the two vectors with angleTo
. Convert it to degrees, where the Y value determines the North/South aspect of your result.
While normalized vectors can be used for comparisons, visualizing the process with surface points on the sphere seems more straightforward.