Robot Motion Calculation: Distance, Direction, Turn Angle
Learn how to calculate robot motion: split each move with cos and sin, predict the position, and find the distance, direction, and turn angle to a goal.

Summary
- From a robot's heading θ and distance d, you can split each move into motion along the x and y axes fixed to the floor: Δx = d × cos θ and Δy = d × sin θ.
- Add each move's x and y changes to the starting coordinates to predict the robot's current position. Use goal − current position to find the distance and direction, then decide the turn angle from the difference between the direction to the goal and the current heading.
- In the robot simulator Webots, when the robot used the position predicted before moving, the gap between where it stopped and the goal was 13.0 mm and 13.1 mm in two runs. When it used the position estimated while driving, the gap was 6.5 mm both times.
For a warehouse transport robot to head to the next shelf, which way should it turn, and how many meters should it drive? First, find the current position from the directions and distances the robot has already moved. Next, find the distance and direction to travel from the shelf's position and the current position, and calculate the turn angle based on the robot's current heading. This article skips the formal proofs and walks through these steps with everyday analogies and worked examples.
Describing a Robot's Movement as "Which Way and How Many Meters"
A robot's position is expressed as coordinates (x, y), using x and y axes fixed to the floor. At the start, the positive x-axis points straight ahead of the robot, and the positive y-axis points to its left. These axes stay fixed to the floor as the robot turns. Heading is measured from the positive x-axis, which is 0 degrees. Counterclockwise (left) angles are positive, and clockwise (right) angles are negative.
On a street grid, you can describe a destination as a certain number of blocks east and north of your starting point. A robot's diagonal move can be described the same way, by how much its x and y coordinates change. These changes are written as Δx and Δy. Then, no matter how many moves the robot makes, you can predict its current position simply by adding the x and y movements to the starting coordinates. The idea of adding moves as arrows is explained in the article on robot vectors and the dot product.
ROS (Robot Operating System, a set of software tools for building robots) uses a different set of axes that turn with the robot. REP 103, a ROS convention document, defines these body-fixed axes. On those axes, x points forward from the robot, y points to its left, and the heading value increases as the robot rotates counterclockwise.
Splitting a Move of Distance d in Heading θ into Δx and Δy
Let θ be the heading the robot travels in and d the distance it travels. θ is the angle measured from the positive x direction of the floor axes. If Δx is the change in the x coordinate and Δy is the change in the y coordinate, they are found with these formulas:
Δx = d × cos θ Δy = d × sin θ
For example, a move of 0.4 m in a heading of 30 degrees works out as follows.
| Item | Calculation | Result |
|---|---|---|
| Δx (x direction) | 0.4 × cos 30° | About 0.3464 m |
| Δy (y direction) | 0.4 × sin 30° | 0.2 m |
Some headings give results that are easy to read. At 0 degrees, the robot moves along the x-axis (its front at the start), so Δy = 0. At 90 degrees, it moves along the y-axis (its left at the start), so Δx = 0. Calculating these two headings first is an easy way to check that the formulas match your intuition.
Python's cos and sin take angles in radians (the unit for angles that these math functions use instead of degrees). If your heading is in degrees, such as 30 degrees, use radians to convert it first. If you pass the value in degrees, you get completely different movement values.
Adding Up Moves to Predict the Current Position (Dead Reckoning)
Once you know the movement values, you can predict the current position by adding each move, in order, to the starting point. This method is called dead reckoning.
Consider a robot that starts at (0, 0) and makes the following two moves.
| Move | Heading θ | Distance d | (Δx, Δy) | Predicted position after the move |
|---|---|---|---|---|
| Move 1 | 0 degrees | 0.3 m | (0.3, 0) | (0.3, 0) |
| Move 2 | 90 degrees | 0.4 m | (0, 0.4) | (0.3, 0.4) |
(0.3, 0) + (0, 0.4) = (0.3, 0.4), so after the two moves, you can predict that the robot is at (0.3, 0.4).
However, if the actual motion differs from the planned move, the predicted position drifts away from the actual position. Because the error from one move carries over into the next calculation, the gap can grow as the moves add up.
Finding the Distance and Direction from the Difference to the Goal
Once you know the current position, the next step is to calculate the way to the goal. The first thing to find is the difference goal − current position.
If the goal is G (0.6, 0) and the current position is (0.3, 0.4), the difference is:
G − current position = (0.6 − 0.3, 0 − 0.4) = (0.3, −0.4)
The x and y differences give the two sides of a right triangle, so the Pythagorean theorem gives the straight-line distance to the goal. The direction to the goal is the angle that the arrow from the current position to the goal makes with the positive x-axis of the floor. For the direction, pass the differences to atan2 (a math function that turns the x and y differences into an angle) with the y difference first and the x difference second. It returns an angle in radians, in the range −π to π. The table shows that angle in degrees.
| What to find | Calculation | Result |
|---|---|---|
| Distance to the goal | √(0.3 × 0.3 + 0.4 × 0.4) | 0.5 m |
| Direction to the goal | atan2(−0.4, 0.3), converted to degrees | About −53.13 degrees |
Python's hypot gives the same straight-line distance when you pass it the x and y differences.
atan2 uses the signs of both differences, so it gives the correct direction in any quadrant of the floor axes. How to use atan2 is explained in the article on robot trigonometry and atan2.
Finding the Turn Angle with "Direction to the Goal − Current Heading"
The direction to the goal and the robot's current heading are both measured from the floor's positive x-axis. Subtract the current heading from the direction to the goal to find how far the robot needs to turn:
Turn angle = direction to the goal − current heading
In the earlier example, after Move 2 the robot is facing 90 degrees (its left at the start). The direction to the goal is about −53.13 degrees, so
−53.13 − 90 = −143.13 degrees
Because the value is negative, the robot turns 143.13 degrees to the right, then drives 0.5 m to reach the goal.
When you calculate a turn angle, you can get a value below −180 degrees or above 180 degrees. A 270-degree left turn and a 90-degree right turn leave the robot facing the same way. If the result falls outside −180 to 180 degrees, express it as an equivalent angle within that range before you use it. This prevents the robot from turning the long way around.
- red: move 1
- green: move 2
- dashed blue: the way to G
- yellow: predicted positions, purple: G
Negative: turn right (clockwise).
Examples for Japanese Companies in the Philippines
These hypothetical examples show how the same calculations apply in warehouses, delivery aisles, restaurants, and factories.
Warehouse: Adding Up Moves to Find the Way to the Next Shelf
Suppose a transport robot drives 30 m in a heading of 0 degrees, then 40 m in a heading of 90 degrees. Adding the moves gives a predicted position of (30, 40). If the next shelf G is at (0, 80), the difference is (0 − 30, 80 − 40) = (−30, 40), and the distance is 50 m. The direction is atan2(40, −30), about 126.87 degrees. Since the current heading is 90 degrees, the turn angle is about 36.87 degrees (positive, so turn left).
Delivery: Splitting a Diagonal Aisle into Δx and Δy
For a robot driving 20 m along a diagonal aisle in a heading of 60 degrees, Δx = 20 × cos 60° = 10 m and Δy = 20 × sin 60° ≈ 17.32 m. Add these x and y changes to the corresponding coordinates to update the robot's predicted position.
Restaurant: A Serving Robot Finds the Distance and Direction to a Table
Suppose a serving robot is at (2, 1), facing 0 degrees, and table G is at (5, 5). The difference is (3, 4), the distance is 5 m, and the direction is atan2(4, 3), about 53.13 degrees. Since the current heading is 0 degrees, the turn angle is 53.13 degrees (to the left).
Factory: Preparing for Errors That Add Up
If each move is off by 1 cm and those errors all add up in the same direction, 20 moves give a total error of 1 × 20 = 20 cm. In places where the robot repeats the same moves many times, such as factory aisles, you need a way to check the current position again along the way, for example with markers on the floor.
Webots Test Results: How the Position Estimate Affects Where the Robot Stops
When I plan a robot's movement with calculations, I check it with this standard: predict the result with formulas first, run it, and judge the gap from the prediction as a percentage (within 5% passes). I tested this calculation in the robot simulator Webots (R2025a) using a robot called the e-puck. Here, I compared the distance calculated to the goal with the distance the robot actually drove, and the check passed if the difference was within 5% of the calculated distance.
Conditions
- The robot is an e-puck (wheel radius 0.02 m), and basicTimeStep, the interval at which the simulation updates, is 32 ms.
- I read the robot's heading from the yaw angle (the left-right rotation) of the InertialUnit, a sensor that measures the robot's orientation. To measure where the robot stopped, I used the Supervisor, which returns coordinates inside the simulation. How to use the Supervisor and encoders (sensors that count how far the wheels have turned) is explained in the Webots simulation tutorial.
- Starting at (0, 0) with a heading of 0 degrees, the robot drives 0.3 m at 0 degrees in Move 1 and 0.4 m at 90 degrees in Move 2, then heads to the goal G (0.6, 0).
- For each move, the robot first turns in place at 2.0 rad/s. When 10 degrees remain to the target heading, it slows to 0.5 rad/s, and it stops turning once the angle difference is within 1 degree. It then drives with the wheels turning at 4.0 rad/s, reading wheel rotation from the encoders to find the distance traveled. While driving, it estimates its current position by adding up the movement over short intervals.
- The only thing I changed was the current position used to calculate the move to the goal G. I tested each condition in two trials. In the results, "Run 1" is the condition that used the position predicted before moving, and "Run 2" is the condition that used the position estimated while driving.
The e-puck in the foreground is at the starting point (0, 0). The yellow markers are the predicted positions (0.3, 0) and (0.3, 0.4), and the magenta marker is the goal G (0.6, 0).
Calculation Before Moving
The values calculated before moving match the calculations explained earlier in this article.
| Item | Calculated value |
|---|---|
| Move 1 | cos 1.0000, sin 0.0000 → (Δx, Δy) = (0.3000, 0.0000), predicted (0.3000, 0.0000) |
| Move 2 | cos 0.0000, sin 1.0000 → (Δx, Δy) = (0.0000, 0.4000), predicted (0.3000, 0.4000) |
| G − predicted | (0.3000, −0.4000), distance 0.5000 m, direction −53.13 degrees |
| Turn angle | −143.13 degrees |
Run 1 (using the prediction made before moving). Table A shows the calculation before moving, and Table B shows the results. The gap from G was 13.0 mm and 13.1 mm.
Position After the Two Moves
After the two moves, the true position measured with the Supervisor was (0.3072, 0.4006) to (0.3073, 0.4006). That was 7.2 to 7.3 mm off from the predicted position (0.3, 0.4). The estimated position, found by adding up the movement while driving, was (0.3068, 0.4000) to (0.3068, 0.4001). Its difference from the true position was 0.8 to 0.9 mm.
How the Robot Reached the Goal G
| Item | Run 1 (prediction before moving, 2 trials) | Run 2 (estimate while driving, 2 trials) |
|---|---|---|
| Difference to G (calculated) | (0.3000, −0.4000) | (0.2932, −0.4000) |
| Distance and direction | 0.5000 m, −53.13 degrees | 0.4960 m, −53.76 degrees |
| Angle turned | −142.21 degrees | −142.84 degrees and −142.85 degrees |
| Distance driven | 0.5005 m | 0.4966 m |
| Stop position | (0.6125, 0.0033) and (0.6127, 0.0033) | (0.6058, 0.0030) (both runs) |
| Gap from G (result) | 13.0 mm and 13.1 mm | 6.5 mm (both runs) |
Run 2 (using the estimate made while driving). The distance to G was calculated as 0.4960 m and the direction as −53.76 degrees, and the gap from G was 6.5 mm both times.
In Run 1, the robot turned −142.21 degrees rather than the calculated −143.13 degrees. Its heading before the turn was 89.08 degrees, not the 90 degrees used in the calculation, so the turn came out to −53.13 − 89.08 = −142.21 degrees. Because the turn angle is calculated as "direction to the goal − current heading," even a slight difference in the current heading is reflected automatically.
The gap between the stop position and the goal G was 13.0 mm and 13.1 mm in Run 1, which used the prediction made before moving. In Run 2, which used the estimate made while driving, the robot stopped 6.5 mm from the goal in both trials. That was 6.5 mm less than the 13.0 mm gap in the first Run 1 trial, a 50% reduction.
When the robot uses the prediction made before moving, the position error from the first two moves is not reflected in the calculation for the move to G. When it uses the estimate made while driving, it can calculate the distance and direction to G from a position estimated from the wheel rotation.
The left side is a top-down view of the floor, showing Move 1, Move 2, the way to G, and the stop positions. The right side is a bar chart of the gap from G for each run.
I applied the within 5% pass criterion to the difference between the distance the robot drove toward G and the calculated distance. The percentages are:
- Run 1: (0.5005 − 0.5) ÷ 0.5 × 100 = 0.1%
- Run 2: (0.4966 − 0.496) ÷ 0.496 × 100 ≈ 0.121%
The distance driven met the 5% criterion under both conditions. The robot stopped closer to the goal when it used the position estimated while driving.
Why Robots Need to Recheck Their Position
In the Webots test, the position estimated by adding up movement while driving got the robot closer to the goal. However, the estimated position can still drift as errors from successive moves carry over. In ROS, REP 105 describes odom as a coordinate frame based on sources such as wheel odometry, which estimates movement from wheel rotation, or an inertial measurement unit. It provides an accurate short-term reference, but drift makes it unsuitable as a long-term reference.
REP 105 also describes a map frame in which the robot's position is recalculated using sensor observations. This corrects drift, though a new observation can cause a sudden change in the reported position. When you consider adopting robots, it is important to plan for both the calculated movement and a system for checking the position again.
FAQ
Q: Should I calculate angles in degrees or radians?
You can think about angles in degrees, but Python's cos, sin, and atan2 use radians. If your heading is in degrees, use radians to convert it before passing it to cos and sin. The angle that atan2 returns is also in radians. To display it in degrees, convert the return value to degrees.
Q: How do I tell whether a turn angle is positive or negative?
Under the convention in this article (the positive x direction is 0 degrees, and counterclockwise is plus), a positive turn angle means turning left, and a negative one means turning right. For example, "−143.13 degrees" means turning 143.13 degrees to the right, and "36.87 degrees" means turning 36.87 degrees to the left. If a calculated value falls outside −180 to 180 degrees, bring it back into that range before using it.
Q: What is the difference between a predicted position and an estimated position?
A predicted position is calculated before moving: "if the robot moves as planned, it should be here." In this Webots test, the predicted position came from the planned moves. For the estimated position, the robot used encoder readings while driving to calculate small movements and added them up. In this Webots test, calculating the way to the goal from the estimated position reduced the gap from the goal from 13.0 mm to 6.5 mm.
Q: When bringing robots into our business operations, what should we check first?
Start by checking how the robot calculates its current position and how often it checks that position again. Asking the manufacturer or reseller questions like these before adoption makes it easier to estimate the operational workload:
- After how many moves between warehouse shelves does the robot check its position again?
- How does a serving robot register the positions of tables?
- Do we need to place markers on the factory floor?
Conclusion
A robot's movement can be calculated by splitting it, from the heading θ and distance d, into Δx = d × cos θ and Δy = d × sin θ. Adding up the changes in x and y gives the robot's predicted position, and the difference goal − current position gives the distance and direction. The turn angle is direction to the goal − current heading.
At the same time, in the Webots test, using the position estimated while driving, rather than the position predicted before moving, made the robot stop closer to the goal. On real sites, it is important to assume that errors will add up and to build a way to check the position again into the system design.
At PH AI Works, we support AI adoption, business automation, and web development for small and medium-sized businesses from our base in Manila, Philippines. If you're considering robots or automation for a warehouse, factory, restaurant, or similar setting, book a free consultation.
References
About the author

Founder / AI Engineer (36+ years in IT)
- ●From Tokyo · based in Manila for 13+ years
- ●36+ years in IT (development, SEO, AI)
- ●Google Certified AI Professional
- ●IBM Certified Generative AI Engineer
- ●AI chatbots, RAG & AI agent development
- ●Physical AI Engineer
A Japanese AI engineer with 36+ years in IT and 13+ years on the ground in the Philippines. I write from hands-on experience to help Japanese companies adopt AI that actually delivers results — chatbots, workflow automation, AI agents, and AI-driven marketing. Feel free to reach out in Japanese or English.
Your Competitors Are Already Using AI!
Is your business keeping up?
Related Articles

Robot Friction and Acceleration: Wheel Spin and Slide
Learn robot friction and acceleration basics, from F = ma and the μmg friction limit to torque and tipping, then predict wheel spin and slide in Webots.
11/30/2026

Robot Vectors and the Dot Product: Predicting Motion
See how vector addition predicts where a robot ends up, how normalization gives direction, and how the dot product tells if a target is ahead or behind.
11/28/2026

Robot Trigonometry: How atan2 Finds a Target Heading
How robots find distance, get a target heading with atan2, and take the shorter turn, plus a Webots test of turning times with and without normalization.
11/26/2026

Robot Control Basics: Conditional Branches and Loops
How a robot runs a sense-decide-act loop, and how to set stop, slow-down and time-limit conditions, using run-time estimates and tests in the Webots simulator.
11/26/2026

Robot Experiment Graphs and Repeatability in Webots
How to change one condition at a time in a robot experiment, read wheel speed and distance on a graph, and check repeatability in the Webots robot simulator.
11/24/2026

Robot Motion in Functions and Graphs: Tested in Webots
See how robot wheel motion fits proportional, inverse, linear, quadratic, exponential and log functions, and how each held up in our e-puck tests in Webots.
11/24/2026
