I have a bit of a problem. I'm working on something and need relative position, relative velocity and relative acceleration in vessel-local coordinates.
I managed getting the vessel-local relative position, but I'm having problems with velocity and acceleration.
The SDK gives you the ability to get global relative velocity and acceleration, but I haven't found a way to turn them to vessel-local relative coordinates.
VESSEL::GlobalRot is able to turn a vessel-local vector into a global vector. According to API reference, it's defined as:
r-global = R * r-local + p-vessel
where r-global is the global vector, R is the rotation matrix, r-local is the vessel-local vector and p-vessel is global vessel position. So the next thing that came to mind was this:
r-local = (r-global - p-vessel) / R
The problem with this formula is that it's somewhat undefined, because even if you're able to get the inverse of the rotation matrix, you still do not know if it's supposed to be
r-local = (r-global - p-vesse)*R^-1
or
r-local = R^-1 * (r-global - p-vessel)
I also tried using Local2Global and Global2Local to get the target's vessel-local velocity into global and then into current vessel's local system, but that didn't work. It seems to have a component of location. I tried subtracting the vessel-local relative position, which got almost correct results, but it seemed to be wrong overall.
So, anyone have any idea on how to turn a global vector into a vessel-local vector?
I managed getting the vessel-local relative position, but I'm having problems with velocity and acceleration.
The SDK gives you the ability to get global relative velocity and acceleration, but I haven't found a way to turn them to vessel-local relative coordinates.
VESSEL::GlobalRot is able to turn a vessel-local vector into a global vector. According to API reference, it's defined as:
r-global = R * r-local + p-vessel
where r-global is the global vector, R is the rotation matrix, r-local is the vessel-local vector and p-vessel is global vessel position. So the next thing that came to mind was this:
r-local = (r-global - p-vessel) / R
The problem with this formula is that it's somewhat undefined, because even if you're able to get the inverse of the rotation matrix, you still do not know if it's supposed to be
r-local = (r-global - p-vesse)*R^-1
or
r-local = R^-1 * (r-global - p-vessel)
I also tried using Local2Global and Global2Local to get the target's vessel-local velocity into global and then into current vessel's local system, but that didn't work. It seems to have a component of location. I tried subtracting the vessel-local relative position, which got almost correct results, but it seemed to be wrong overall.
So, anyone have any idea on how to turn a global vector into a vessel-local vector?