Sign in to follow this  

Calculating relative angular velocity for missile lock on...

This topic is 3449 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

SO, I had this function to calculate whether or not a target can be "tracked" by a spaceship's missile launcher. (This is a pseudocode version)
function tgtIsTrackable (tgt as Object, me as object, coverage As Single, range As Single, trackingrotspeed As Single) As Integer

	vector RelativeVelocity = vecSubtract(Tgt.Velocity, me.Velocity)
	bool WithinCone = PointIsWithinCone (Tgt.Coords, me.Coords, Me.ForwardVector, Coverage, Range)
	
	bool SlowEnough = ((magnitude(RelativeVelocity) / distance (Tgt.Coords, me.coords)) <= (TrackingRotSpeed))
	
	If WithinCone And SlowEnough Then Return TRUE
end function
PointIsWithinCone is a function that returns TRUE if a point is within an area defined by a vector (Forward), a distance (range), and an angle (coverage). SlowEnough is set to TRUE if the angular velocity of the target (relative to Coords) is less than TrackingRotSpeed -- the speed (in rad/sec) at which the launcher can track a target. (It's based on the fact that LinearVelocity = AngularVelocity*Radius. In this case, LinearVelocity is RelativeVelocity, Radius is the distance between the two objects, and I'm solving for AngularVelocity). This works perfectly if my ship is not rotating. However, I've come to realize that I have to take into account MY rotational velocity, since my current rate of rotation will have an effect on whether or not I can track the target. In 2D, I'd simply add my rotation rate to my TrackingRotSpeed to come up with a a value that represents how fast the launcher is tracking the target. However, this is a 3D game, and my rotation rate is stored as three euler angles. I'm not sure how to make this work. Thanks...

Share this post


Link to post
Share on other sites
Quote:
my rotation rate is stored as three euler angles. I'm not sure how to make this work.

Me neither. I'm going to use a vector for my part of the discussion. The direction of the vector is the axis upon which "me" is rotating. The magnitude of the vector gives its rotational velocity in radians/sec.
Also, velocity/distance = 1/time. Oh, wait, that's actually almost the correct unit for comparison; never mind. Do keep in mind that one rotation equals 2*PI radians.
You're doing the same thing in 3d that you would do in 2d but there's more to it.
Use the relative linear velocity(in meters) of the target to determine a fake rotational velocity(in rad/sec). To do this, "relative" means relative to the tracking ship, find the relative linear velocity(vector, m/s) of the target and the relative distance(vector, in meters). Perform a cross product. This gives you the fake rotational velocity of the target(vector). Take this result and do a dot product with the tracking ship's rotational velocity vector. Take that result(magnitude, rad/sec) and subtract it from the target's fake rotational velocity magnitude. Compare that result with the maximum rotational velocity magnitude that the ship's tracker can perform(rad/sec). If the tracker's max is higher, the target can be tracked.

Share this post


Link to post
Share on other sites
Interesting. I think my terminology was wrong when I said I was storing the rotational velocity as "Euler angles." What I am using is this:

AngularVelocity = Vector ( AngularVelocityAroundX, AngularVelocityAroundY, AngularVelocityAroundZ )

It looks like I wasn't all that far off. I'll try this as soon as I get back to a coding machine.

Thanks a lot

Share this post


Link to post
Share on other sites
v = w x r
v = linear velocity of point
w = angular velocity of point (supposed to be lowercase omega, not "w")
x = cross product operator
r = position of point

so I think it's safe to change it to
w = r x v
I have nothing to base this on though except
i × j = k j × k = i k × i = j.
So r might be from the target to the tracker.

Share this post


Link to post
Share on other sites
Ok, this is going to involve a bit of math so stick with me here. The overall strategy is this: 1) first we will define all the terms. 2) Next we are going to write the velocity vector of the target in the coordinate system of the ship. In other words, how would someone on the ship describe the way the target is moving. 3) Finally, we will use this to calculate the angular velocity of the target in the ship's coordinate system.

Ready? Here we go!
1)
Here are the initial definitions (these are all vectors unless otherwise specified):
Known:
* s - position of the ship in ambient space coordinates
* t - position of the target in space coordinates
* vs - velocity of the ship in space coordinates
* vt - velocity of the target in space coordinates
* the euler angles
* the first derivatives of the euler angles

Unknown:
* r(space) - displacement from the ship to the target in space coordinates
* v(space) - relative velocity of the ship and target, written in space coordinates
* ws - the angular velocity of the ship (in space coordinates of course)
* r(rotating) - displacement from the ship to the target, written in the rotating coordinates of the ship
* v(rotating) - relative velocity of the ship and target, written in the rotating coordinates of the ship

Goal:
* wtr - the angular velocity of the target relative to the ship, written in the ship's rotating coordinates
* wtr - magnitude of wtr
--

2)
The relative positions and velocities in space coordinates are found by subtracting that of the ship from the target:
r(space) = t - s
v(space) = vt - vs

ws, the angular velocity of the ship, can be found from the euler angles and the first derivatives of the euler angles by using equation 21 on the following page:
http://mathworld.wolfram.com/EulerAngles.html


To convert the relative velocity in the space coordinates into the rotating ship coordinates, use the main equation of rotating coordinate systems, which says that
v(rotating) = v(space) - ws x r

This is the velocity vector of the target in the coordinate system of the ship.
--

3)
wtr, the angular velocity of the target in the ship's coordinate system, may be found with the following equation:
wtr=( r(rotating) x v(rotating) )/length( r(rotating) )^2

The magnitude of the angular velocity of the target from the perspective of a person on the ship is then just wtr, then length of wtr.

Whew. Hopefully I didnt make any mistakes there.

[Edited by - Maze Master on July 8, 2008 10:30:07 PM]

Share this post


Link to post
Share on other sites

This topic is 3449 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this