#### Archived

This topic is now archived and is closed to further replies.

# bots direction

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

## Recommended Posts

Hi Currently, my bots are correctly navigating between waypoints as they should. Now the problem i have is making them facing the direction they are walking. I already get the angle that they must rotate.., please, look at this: P3..........P2...........P4 ............P1 Ok.., my bit is in waypoint P1, and going to P2. I have 3 vectors here.. P1-P2 / P2-P3 / P2-P4 The angle between P1-P2 and P2-P3 is 90 degrees, as it is between P1-P2 and P2-P4.,.., so far so good. Now, my problem is findind the direction of rotation., if my bot is going to P3 i must rotate -90, if going to P4 i must rotate 90...., Anyone knows a way to find out the sign of rotation ? thanks.., Bruno

##### Share on other sites
To get from an x and y vector to an angle, use the arctangent function. atan2() is probably your best bet.

##### Share on other sites
If you define your vectors as:
v = line(P1,P2)
w1 = line(P2,P3)
w2 = line(P2,P4)

then the following holds

p = -q

where
p = v x w1
and
q = v x w2

the ''x'' means vector cross product.

You can use this sign difference to distinguish between w1 and w2 and hence determine a +1 or -1 multiplier to the 90 degrees angle to get your bot to turn in the correct direction.

Cheers,

Timkin

1. 1
Rutin
36
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 98
• 11
• ### Forum Statistics

• Total Topics
632974
• Total Posts
3009651
• ### Who's Online (See full list)

There are no registered users currently online

×