Angles between dots doesn't make sense, so you probably mean something slightly different.
I would imagine that you actually have this information:
1) You have the position co-ordinate of an enemy.
2) You have the position co-ordinate of your bot
3) You have the direction vector of your bot
Firstly, translate all of these into vectors; you have 2 position vectors and 1 direction vector.
Now you need to make your calculations relative to the bot position vector, so subtract the position vector of the bot from the position vector of the bot and the position vector of the enemy (store these in some temporary vector variables, by the way). Now you have a direction vector and the position vector of the enemy relative to the bot position.
It is simple to find the angle between the two now by using the property that:
a .
b = |
a||
b|cos(theta)
Rearrange:-
cos(theta) = (
a .
b) / |
a||
b|
Now it is simple to find an expression for theta (the angle that your bot has to turn):-
theta = arccos((
a .
b) / |
a||
b|)
Here is a bit of untested pseudo-code:-
[syntax="QBASIC"]
TYPE Vec2D
x AS SINGLE
y AS SINGLE
END TYPE
...
' Assuming we have 3 vectors here:- the direction vector of the
' bot (bot-dir), the position vector of the bot and the position
' vector of the enemy.
DIM enemyRelativePosition AS Vec2D
enemyRelativePosition.x = enemyPosition.x - botPosition.x
enemyRelativePosition.y = enemyPosition.y - botPosition.y
' Since the direction vector is already relative to the bot position,
' we don't need to translate it.
dotProduct! = (enemyRelativePosition.x * botDirection.x) + (enemyRelativePosition.y * botDirection.y)
modDirection! = SQR((botDirection.x * botDirection.x) + (botDirection.y * botDirection.y))
modRelativeEnemyPosition! = SQR((enemyRelativePosition.x * enemyRelativePosition.x) + (enemyRelativePosition.y * enemyRelativePosition.y))
' Calculate the value of COS(theta!)
cosTheta! = dotProduct! / (modDirection! * modRelativeEnemyPosition!)
' QB only gives us arctan, which is a pain in the arse.
' So, anyway, did some working and this should work to get
' theta out of COS(theta) using ATN.
'
' Here is my working for this:
'
' tan x = (sin x) / (cos x)
' Thus: tan^2 x = (sin^2 x) / (cos^2 x)
'
' sin^2 x = 1 - cos^2 x
'
' Thus: tan^2 x = (1 - cos^2 x) / (cos^2 x)
' Thus: tan x = SQR((1 - cos^2 x) / (cos^2 x))
'
' And finally: x = ATN(SQR((1 - cos^2 x) / (cos^2 x)))
'
tanTheta! = SQR( (1 - (cosTheta! * cosTheta!)) / (cosTheta! * cosTheta!) )
' Finally, we can find theta.
theta! = ATN(tanTheta!)
' This is the angle that we need to turn to face the enemy.
[/syntax]
Like I said, untested code, but the theory, as far as I know, is correct. I tried to explain it quite a bit so hopefully it's okay to follow.
-shiftLynx