Jump to content

Given a position vector, what body's SOI is it inside of?


Recommended Posts

What the title says. I'm looking for an API method that will let me pass in a position vector (expressed in Unity World Coordinates), and tell me which body's sphere of influence that position is in. I can ask what sphere of influence a vessel is in, but this isn't necessarily a vessel's position - it's just an arbitrary position in space.

(Background: I'm trying to make a homemade raycast algorithm that works to find where a ray hits the body's terrain, when the intersect in question is far enough away that the terrain polygons are not loaded so I have to use the PQS controller to get the terrain data instead of using Unity's Raycaster to hit the polygon. One important part of that algorithm is to simply figure out which Celestial Body the ray's origin is located in in the first place.)

Link to comment
Share on other sites

Would it be possible to loop through all celestial bodies, get their position and radius of SoI, then work out if your position is inside that sphere?

Ugh. Yes, technically possible. But the Mun's SoI is a pocket inside Kerbin's SoI which is a pocket inside Sun's SoI. So using the technique you describe, a point inside the Mun's SoI would register 3 SoI hits - one for Mun, one for Kerbin, and one for Sun. I'd have to be careful to always make sure that of all the hits I get, I use the one that's at the lowest tier of the tree structure of bodies.

Link to comment
Share on other sites

The only other think I can think of is to 'spawn' a null vessel, then call the .body method on it.

Otherwise, I think blizzy's suggestion is the only other way I can think of.

D.

edit: Wait, you know the world co-ordinates of your point, what about a simple list compare of distances as the SOI boundary is a fixed distance.

(On proof reading before posting, I realize this is essentially blizzy's suggestion, just you premake the list of SOI distances to compare to and check the shortest distance first rather then calculating them.)

So sort the list by shortest distance to your point and then error trap to make sure you are inside that body's SOI distance.

(For this example, Mun's SOI is 300km, Kerbin's is 1,000km)

Distance check, we are closest to the Mun at 55km from the Mun. 55km is less then the Mun's SOI boundary so we are in the Mun's SOI.

Distance check 2, we are closest to the Mun at 350km from it. 350km is greater then the 300km SOI boundary so check next closest. Next closest is Kerbin at 800Km from our point in space. 800km is less then 1,000km so we are in Kerbin's SOI.

Edited by Diazo
Link to comment
Share on other sites

Check all of CB Sun's children. If it's in one of their SOIs, check that body's children to see if it's in that SOI. Keep drilling down.

I'm not too familiar with the O's, but yeah, that's basically it. Your list of bodies to check (parent-child relationships) is essentially fixed, and you can even build that dynamically at KSP start (to account for planet mods.)

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...