Search code examples
pythonsimulationgeometryangleatan2

get angles using atan2 on circle for robot simulation


I am doing a simulation on a robot that makes circular motion with a center coordinate (x1, y1). The robot measures its position periodically and returns the information. Let's say the returned coordinate is (x3, y3). However, I'm not too sure about the correct way of using atan2 in python to calculate the angles between the current measurement and the last measurement with the center.

so far, I am doing the following, and would like to confirm if it's right:

current_angle = atan2(y3-y1, x3-x1)
last_angle = atan2(y2-y1, x2-x1)
angle_difference =  current_angle - last_angle

With the angle_difference, I then calculate the angular velocity = angle_difference / dt (dt is the time spent between the last measurement and the current measurement)


Solution

  • Almost correct. The formula as given will have trouble when passing across axes between the first and fourth quadrants and the second and third quadrants, so you need to take the minimum of the absolute values of the differences of the angles instead, and then compensate for sign.