Closest Point on globe to screen space.

Good Afternoon,

I'm trying to figure out the best way to find the closest point on the globe to a position in screen space if the position in screen space is not on the glove. Basically I need to draw a rectangle in screen space, and send over the rectangle to a server to do some intersection testing, however I need it to be in latitude and longitude, not screen space coordinates. Any help is greatly appreciated!


Paul Greaney

I’m pretty sure we don’t have a function that does what you want, but I’ll try to confirm that one way or the other. Can you help me better understand your use case? Is someone interactively drawing the rectangle? Do you have some points of the rectangle on the globe and some points off?

Someone is actively drawing the rectangle. I have the case covered where there are either start points or end points that end on the globe. My issue is what if they start and end off the globe. I’d need to find the closest point on the globe to where the screen rectangle starts and ends. The main reason I need this is there is no way to convert a point in space to a cartographic to my knowledge(as it’s not on the world therefore how can it have a cartographic location? haha).

Would it be possible to just consider those selections invalid and make the user repick? Even if we do have such a function, I have a feeling that if the entire rectangle is off of the globe, the resulting points closest may not be anywhere near where the user is looking (depending on the current view),

I should clarify that the globe will be inside the rectangle. If they make a rectangle that is just nothing but space then that is on the user

I think I’ve found a solution; get the mouse’s cartesian position, then convert it to cartographic. This spits out what SEEMS to be a valid cartographic mouse position, and then I can pass that over to the server to check if the points I want to return are within the start mouse position and end mouse position.

That did not even slightly work, haha.

Since you said “the globe will be inside the rectangle”, does that mean you are always just making a big rectangle around the entire earth?

Not always, but there will always be part of the rectangle encompassing the earth

Sorry for never getting back to you on this. Thinking about it some more, if you have at least one point on the globe, you could estimate the rectangle using camera.frustum.getPixelSize. You would then use the length/width height of the rectangle in pixels to create an equivalent Cesium rectangle using the known point on the globe as the anchor point. I think that would give relatively good results, regardless of view angle.