Imagine this three.js scene, set up with an OrthographicCamera and OrbitControls:
When the user drags the yellow disc (meant to represent the Sun), the disc needs to move along its yellow circle in response to this action. Here’s the scene from another angle, so you can see the full yellow circle:
So, my event handler must determine which point on this circle is closest to the current cursor position. This yellow circle is a THREE.Mesh, by the way.
I’m using THREE.Raycaster to determine some mouseover events, using its
intersectObjects() function, but it’s not clear to me how to find the nearest point of a single object with this Raycaster. I’m guessing there is some simple math I can do after translating the mouse’s position to world co-ordinates. Can someone help me with this? Is Three.js’s Raycaster useful here? If not, how do I determine the nearest point of this mesh?
The full source code is here, if it’s helpful: https://github.com/ccnmtl/astro-simulations/blob/master/sun-motion-simulator/src/HorizonView.jsx Search for
this.sunDeclination , which corresponds to the yellow circle’s Mesh object.
For a working demo, go here: https://ccnmtl.github.io/astro-simulations/sun-motion-simulator/
For reference, the sun should behave like this: https://cse.unl.edu/~astrodev/flashdev2/sunMotions/sunMotions068.html (requires Flash)