# Finding the Correct Node on a Rotated Sphere

Hi,

I am currently working on procedurally generating spheres at runtime using a subdivided icosahedron.

So far, I have managed to create an icosahedron and subdivide this a specified number of times. I am then mapping the vertices of the subdivided shape as the center points of the hexagons (and 12 pentagons) that are being created, and generating the hexagons from the center points of all adjacent triangles.

These "nodes" (the hexagon center points) are generated at game launch and are static; they never move. When clicking on the surface of the sphere, I loop through all these nodes and find the nearest one to the mouse click and create a simple cube at the center of the hexagon.

This works great when the sphere has a rotation of [0, 0, 0]. Even when the camera is rotated around the sphere at weird angles, the logic holds up for clicking on the surface of the sphere. However, when the sphere itself starts to rotate, the logic breaks down.

I know exactly why this is the case; I am mapping to the position of the nodes (which are static). With the sphere rotating, the nodes no longer map to their visual counterparts (the hexagons) and, as such, the placement logic does not work.

I understand the basic premise for calculating the correct visual placement:

Take the click point on the sphere and rotate the point opposite to the sphere's rotation. This will map my click point back to the original node positions.

Calculate the closest node using the existing logic now that the point is in "node" space.

With the closest node found, map the node's position back to the sphere's rotation so that the cube is placed at the center of the correct hexagon visually.

I have been trying to work this out for a few days but I cannot find how to do this. I believe the main issue relies in rotating my click position in "world" space to "node" space and, then, vice versa when the nearest node has been found.

Is anybody able to help in calculating the mathematical function that is required to convert my point from "world" to "node".

I have looked into Quaternion.Inverse to 'reverse' the sphere's rotation and used the following function to rotate a point around a point (the origin):

```
private Vector3 RotateAroundPoint( Vector3 point, Vector3 pivot, Quaternion rotation )
{
return rotation * ( point - pivot ) + pivot;
}
```

but neither of these methods seem to be working for what I want. The cubes sometimes even place themselves way away from the surface of the sphere, which is definitely wrong!!

Any help would be greatly appreciated as I cannot solve this by myself :)

**Answer** by Scribe
·
May 29, 2018 at 11:57 AM

There are already methods on transform to do this for you fortunately. In step 1 use `sphereTransform.InverseTransformPoint(worldPoint)`

and step 3 you do `sphereTransform.TransformPoint(nodePosition)`

### Your answer

### 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.