Atlas Robotics
Math for RoboticsBasic

Vectors in robotics: position, velocity and the angle between directions

Atlasbot · 17/8/2026 · 10 min read

Vectors in robotics: position, velocity and the angle between directions
Position vector, velocity vector and angle between the two vectors

Before reading any robot kinematics formulas (which appeared in the articles Differential Drive and Odometry), it is necessary to agree on a common mathematical language: vector. The robot's position on the plane, the speed of movement, the direction of the LiDAR scan — all are vectors.

Key concepts

A number (scalar) just carries magnitude — for example "the robot is moving at a speed of 0.5". A vector carries both magnitude and direction — "the robot is moving at a speed of 0.5 m/s in a direction 30° from the x axis". In 2D (plane) robots, vectors are simply written as coordinate pairs:

p = (x, y) # position vector — where the robot is
v = (vx, vy) # velocity vector — moving fast/slow, in which direction

The magnitude of a vector — for example, the actual speed regardless of direction — is calculated using the Pythagoras theorem:

|v| = √(vx² + vy²)

In short: Vector = magnitude + direction, written as a pair of coordinates in 2D space — the core difference from a number (scalar) that only has magnitude.

How it works

Adding two vectors is adding each corresponding component — the physical meaning is sum two movements occurring simultaneously. For example, a robot moving on a conveyor belt: the actual speed relative to the ground is the sum of the robot's velocity vector plus the conveyor belt speed vector:

v_thuc_te = v_robot + v_bang_chuyen
          = (vx1 + vx2, vy1 + vy2)

The dot product between two vectors shows how much they point in the same direction — most commonly used when needing to calculate the angle between two vectors (for example, the angle of deviation between the direction the robot is looking at and the direction it needs to reach its destination):

a · b = ax·bx + ay·by = |a| |b| cos(θ)
θ = arccos( (a · b) / (|a| |b|) )

This is the exact calculation underlying the question "how many degrees should the robot rotate to point towards the next waypoint" that any path following controller must solve.

Technical details

Formulas

Normalization of the vector (normalization) — take unit vector (unit vector) only keep the direction, leave out the magnitude — used when only interested in where the robot is "looking", not interested in speed:

v̂ = v / |v|

VD: v = (3, 4), |v| = √(3² + 4²) = 5
v̂ = (3/5, 4/5) = (0.6, 0.8) ← unit vector, |v̂| always = 1

Parameters

Actual range of velocity vectors on indoor AMR — useful to know "what number is reasonable" when debugging:

Great quantityTypical range of values
linear velocity0 – 1.5 m/s (Indoor AMR, narrow spaces)
Angular velocity-π to π rad/s (~-180°/s to 180°/s)

Practical applications

In addition to dot product (which measures "how much in the same direction"), the 2D directional product (cross product, z component only) indicates whether the robot should turn left or right to head toward the destination — additional information that dot product/arccos does not provide (arccos always returns a positive angle of 0-180°, regardless of direction). rotate):

cross_z = ax·by − ay·bx

cross_z > 0 → b is to the left compared to a (need to turn left)
cross_z < 0 → b shifts to the right relative to a (need to turn right)

Combining dot product (magnitude of deviation angle) and cross product (left/right deviation) is the standard way for the path following controller to calculate exactly how many degrees to rotate, in which direction — using dot product/arccos alone will not be enough information to know whether to rotate left or right.

Practical example

import math

def magnitude(v):
    return math.sqrt(v[0]**2 + v[1]**2)

def angle_between(a, b):
    dot = a[0]*b[0] + a[1]*b[1]
    cross_z = a[0]*b[1] - a[1]*b[0]
    angle_rad = math.atan2(cross_z, dot)   # atan2 retains both magnitude and direction
    return math.degrees(angle_rad)

huong_robot = (1, 0)      # The robot is looking straight along the x axis
huong_toi_dich = (0, 1)   # target lies straight along the y axis (left)

print(f"Goc can xoay: {angle_between(huong_robot, huong_toi_dich):.1f} do")
Output:
Goc can xoay: 90.0 do

A positive result (+90°) indicates that the robot needs to rotate left exactly 90° — using atan2(cross_z, dot) instead of arccos simply solves the problem of losing dimensional information mentioned in the Practical Application section, without needing to calculate the two steps separately.

Common mistakes

  • Use arccos and lose rotation direction information (left/right) — as mentioned above, arccos only returns positive angle 0-180°, don't know whether to rotate left or right — use atan2(cross_z, dot) to get both magnitude and direction in 1 step.
  • Normalize a vector with a magnitude of 0 — dividing by |v| = 0 causes a division by 0 error — occurs when the robot is at the correct target position (vector towards the target is 0), need to check the magnitude before normalizing.
  • Mixing degrees and radians in the same calculation — trigonometric functions in most programming languages (Python math, C cmath) by default recognize radians, passing in the wrong degree causes completely wrong results without reporting an error.
  • Confusion between point and vector — 2 points themselves are not vectors, you have to subtract the target point from the current point to get the direction vector (v = p_dich - p_hien_tai) — directly adding/using point coordinates as vector causes meaningless results.

Conclusion

Vector is the building block of all robotic kinematics formulas behind — Matrix (next article) is nothing more than a tool to transform a series of vectors at once, while Rotation and Transform are both specific vector transformations. Mastering addition, dot product, and 2D cross product is enough to understand how a path following controller calculates the angle to rotate. The next article in this category is about Matrix — a neat way to represent and apply multiple vector transformations at once.

Get new articles and lessons by email

When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.

Unsubscribe any time with the link in each email. See our Privacy policy.

Vectors in robotics: position, velocity and the angle between directions — Atlas Robotics