How to determine that a vector is pointing at a distant object ?

N_Molson

Addon Developer
Addon Developer
Donator
Joined
Mar 5, 2010
Messages
10,002
Reaction score
4,418
Points
203
Location
Toulouse
Hello mathematically-skilled people, :hello:

On my current addon-developpement work, I need to determine if a ship A is pointing at another ship B.

I've got the distance of the ship B relative to the ship A (from their global ecliptic positions), and even calculated the relative rotation angles on the Y & X axis of ship A (when A is perfectly pointing at B, those angles are equal to 0°).

I wonder what would be the mathematical approach to solve that problem. :hmm:

Any suggestions ? :tiphat:
 
Get the global coordinates of B.
Convert those to local coordinates in A's reference frame.

You now have the vector from A to B, in A's reference frame.

Knowing that the z-axis is straight forward, if the vector is of the form <0,0,[value]> you know that A is pointing directly at B.

From there you can decide how much of a "margin of error" is acceptable to you. This can be either in terms of either angle or the ratio between the x/y offset and z, which is the tangent of the angle and simpler to calculate.
 
Thanks, now I got that part. When A is pointing at B, the Z element of the vector is equal to the distance between the two ships.

I have another problem though, well it's a mix of C++ and math I think : I'm coding an autopilot and I want it to "detect" when the vector lenght is the longest between A & B on a given axis. The longest value is not necessary the distance between A & B in that case, because the autopilot has to control only the pitch & yaw axis.

So I'd like it to "scan" an axis then lock on the longest value, then repeat the process on the other axis, and for that I need the autopilot to "store" that longest value. But it is somewhat complex because it is updated every frame...
 
Have you looked into possibly using a PID (or PD, since you can "cheat" with Orbiter and don't really need the integral part)-type controller? For my "point at a target and go" autopilot, I basically used independent pitch/yaw mechanisms with the inputs being the angle to the target and the current speed of rotation (in only that axis) and the output being the necessary RCS level.

The axes end up being independent, and you don't have to remember anything between frames. It might not be the "best" way to do things but it worked out pretty well for my purposes...
 
Like this ?

[ame="http://en.wikipedia.org/wiki/Proportional_control"]http://en.wikipedia.org/wiki/Proportional_control[/ame]

I wasn't even aware of those PID/PD controller algorithms, so intuitively I was in a on/off approach... :tiphat:
 
Like this ?

http://en.wikipedia.org/wiki/Proportional_control

I wasn't even aware of those PID/PD controller algorithms, so intuitively I was in a on/off approach... :tiphat:
For an autopilot, a proportional control won't really do it since you also need to take into account velocity--that's why I mentioned a PD controller, which is a PID controller without the I :)
[ame="http://en.wikipedia.org/wiki/PID_controller"]PID controller - Wikipedia, the free encyclopedia[/ame]

Essentially, the autopilot PD controller's output depends only on the current position and the current velocity. When you break this down by axis you get a fairly simple equation per-axis that's relatively easy to tune.
 
Back
Top