# Talk:Lateral Velocity

I don't understand how the equation works.. Could anyone explain this to me in terms of triangles? What does e.getHeadingRadians() - enemyAbsBearing give? How can you explain it?

---- urgood2 04:25, 21 March 2010 (UTC)

Well, `e.getHeadingRadians()` is the enemy's heading relative to the battle field - 0 is pointing up, Math.PI / 2 (90 degrees) is right, Math.PI (180 degrees) is down. The `enemyAbsBearing` variable is the angle from your bot to the enemy bot. So the difference is the enemy's heading relative to yours - 0 is facing directly away from you, Math.PI / 2 is exactly perpendicular to you (clockwise), etc. Having trouble thinking of some triangles that would demonstrate the formula, probably because it's late on a Saturday night... But hopefully that helps. --Voidious 04:33, 21 March 2010 (UTC)

Let's say: red box are our robot; green box are our enemy, CE is extended CB, and BF and CG always point to the north (0 degrees). The lateral velocity is DB. Enemy velocity is AB. We know AB, and we need to know either angle ABD or angle BAD. We know angle GCB (the enemyAbsBearing) and FBA (e.getHeadingRadians()), so how to get either BAD or ABD? Since BAD + ABD = 90 and ABD + ABE = 90, therefore BAD = ABE. So far CG // BF, since both point at north, so GCB = FBE. FBE - FBA = ABE, thus enemyAbsBearing - e.getHeadingRadians() = ABE. ABE = BAD, so we get what we want.

Hope you understand, I don't know how to express my math in proper English =) --Nat Pavasant 05:49, 21 March 2010 (UTC)

Thanks all! I understand it now... -- Josh S 12:36, 27 April 2010 (UTC)

Is `enemyAbsBearing - e.getHeadingRadians()` the same as `e.getHeadingRadians() - enemyAbsBearing`? The lateral velocity formula on this page uses the second. ---- urgood2 06:39, 21 March 2010 (UTC)

I'm not sure, but I think the sin() make them the same, but I may be wrong. Waiting for some maths wizard to help me (Rednaxela, I'm looking at you =)) --Nat Pavasant 10:08, 21 March 2010 (UTC)

Looking at me? Haha. No, it wouldn't have the same result. It would flip the sign of the resulting lateral velocity. Doesn't really matter so long as it matches what any other code using it expects (i.e. whether 1 is clockwise or -1 is clockwise). --Rednaxela 14:45, 21 March 2010 (UTC)

Well, you have solved many maths problem I or other has posted here, and you are computer-engineering student, and I'm grade nine student =) --Nat Pavasant 05:53, 22 March 2010 (UTC)

Let's assume that we have three known positions: our position last turn, an opponent's position last turn, and the same opponent's position this turn. We can measure the bearings between our position and our opponent's positions, and the distance between our positions last turn. Subtracting the present bearing from the former, we get the change in bearing.

Let's begin with a known distance between our positions last turn of 400.

• At that distance, the change in theta of an opponent moving perpendicular (lateral) to our former position at maximum velocity is atan(8/400), or about 0.019997 radians.
• At that distance, the change in theta of an opponent maintaining distance (orbital) to our former position at maximum velocity is 2asin(4/400), or about 0.020000 radians.

Those numbers are pretty darned close. They are still pretty close at 200 distance. I'll leave it to you to care about using both or one over the other. Moving on..

Finally, let's compare the known change in bearing with those thetas which reflect a deliberate attempt to move in a certain way. Consider a measured theta of -0.015.

• Dividing theta by optimal lateral movement gives us about 0.75113.
• Dividing theta by optimal orbital movement gives us about 0.75000.

Again, not much difference.

The advantage of dividing our known value by the maximum for that distance is that we have a consistent range of [-1,1]. This 'unit' range can be handy when comparing to other measured unit ranges. The K Nearest Neighbors search comes to mind. This commentary could likely use some editing, but I gotta join a 'going for a walk' group. Happy Robocoding! --Martin 22:48, 23 March 2010 (UTC)