Matrices in robotics: transforming many points at once
Atlasbot · 17/8/2026 · 10 min read
Lesson Vector in Robotics said that vector represents a point or a direction. Next question: how to rotate/translate thousands of points at the same time (entire point cloud LiDAR, entire occupancy grid map) according to the same transformation, without writing a loop that calculates each point separately according to the trigonometric formula? The answer is matrix.
Key concepts
A 2×2 matrix multiplied by a 2D vector gives another 2D vector — fixed multiplication rule:
| a b | | x | | ax + by |
| c d | × | y | = | cx + dy |
The important thing: is the same matrix M, multiplying by any vector applies exactly the same transformation. That means if you need to rotate 5,000 LiDAR points by 15°, just calculate a single 15° rotation matrix, then multiply by all 5,000 vectors — no need to re-deduce the trigonometric formula for each point.
How it works
The three most common matrix transformations in 2D robots:
Identity matrix — unchanged:
| 1 0 |
| 0 1 |
Rotation matrix angle θ:
| cos θ −sin θ |
| sin θ cos θ |
Scale matrix according to coefficient k:
| k 0 |
| 0 k |
The rotation matrix is the most used matrix in mobile robots - it is the formula behind the article Rotation when it is necessary to rotate a vector according to the current heading angle of the robot.
In short: Matrix transformation linear — meaning it cannot be used to translate a point, only rotate/scale around the origin (0,0). This is the reason why robotics needs to add the concept of homogeneous transform (Transform lesson) — expanding the matrix to handle translation.
Technical details
Formulas
Matrix multiplication is not commutative — the order of multiplication determines the final result differently, a point that can easily be confused when combining multiple transformations:
M1 × M2 ≠ M2 × M1 (in general)
Example: Rotate 90° then scale by a factor of 2, apply to point (1, 0)
Method 1 (rotate first): M_scale × (M_rotate × p) = M_scale × (0, 1) = (0, 2)
Method 2 (pre-scaling): M_rotate × (M_scale × p) = M_rotate × (2, 0) = (0, 2)
→ This case has the same result (due to uniform scaling by k along all axes), but with
nonuniform scaling along each axis (kx ≠ ky) or more complex transformations,
The 2 orders give 2 completely different results
When combining multiple transformations (M_tong_hop = M_scale × M_rotate), always keep the intended order — changing the order of multiplication means changing the geometric meaning of the transformation.
Parameters
Computational cost when transforming a series of points — the reason robot libraries always include the matrix first and then apply it to the entire data:
| How to do it | Cost for N points |
|---|---|
Recalculate sin/cos (transcendental, slow function) for each point | N times trigonometric function calls — expensive |
| Calculate a rotated matrix once, multiply the matrix (multiplication/addition only) for N points | 1 call of trigonometry + N × (4 multiplications + 2 additions) — much cheaper |
Practical applications
This is exactly what SLAM does in each new LiDAR scan: the raw scan data is in the LiDAR's local coordinate system (lidar_link, learned in lesson TF/TF2 in the ROS/ROS2 section) — before merging into the global map, all thousands of points of 1 scan must be multiplied by the transformation matrix corresponding to the current pose (position + direction) of robot, switching from the local system to the global map system. With LiDAR scanning dozens of times per second, thousands of points at a time, combining the matrix before applying it in bulk (instead of recalculating trigonometry for each point) is the deciding factor in whether SLAM runs fast enough in real time or not.
Practical example
import numpy as np
theta = np.radians(90) # rotate 90 degrees
M_rotate = np.array([
[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]
])
# 3 sample LiDAR scan points (local coordinates)
points = np.array([[1, 0], [2, 0], [0, 1]])
# Rotate all 3 points at the same time using a matrix multiplication
points_rotated = points @ M_rotate.T
print(points_rotated)
Output:
[[ 6.123234e-17 1.000000e+00]
[ 1.224647e-16 2.000000e+00]
[-1.000000e+00 6.123234e-17]]
Approximate result [(0,1), (0,2), (-1,0)] (extremely small error due to rounding of floating point real numbers) — correct confirmation: point (1,0) after rotating 90° becomes (0,1), matching the counterclockwise rotation rule stated in the rotation matrix formula.
Common mistakes
- Wrong order when concatenating multiple matrices — as mentioned in the Formula section, matrix multiplication is not commutative — concatenating in the wrong order (
M_rotate × M_scaleinstead ofM_scale × M_rotate) gives a different geometric result than intended. - Expect the linear matrix to move by itself — as mentioned in the Principle of Operation section, the linear 2×2/3×3 matrix only rotates/scales around the origin of the coordinates, cannot be translated (translate) — needs homogeneous transform (next article) for this.
- Mixing degrees and radians when calculating rotation matrix — similar to the error mentioned in the Vector article, the function
sin/cosin most libraries recognizes radians, forgetting to change the unit gives completely wrong results. - Multiplying 2 matrices of wrong dimensions — 2×2 matrices can only be multiplied with 2D vectors or 2×N matrices, trying to multiply with vectors/matrices of wrong dimensions causes runtime errors in most math libraries (NumPy reports
ValueError: matmul: Input operand has a mismatch...).
Conclusion
Matrix allows the same geometric transformation to be applied to thousands of points with a single repeated multiplication, avoiding the need to recalculate costly trigonometric functions for each point — the computational foundation of any SLAM/point cloud pipeline that processes real-time LiDAR data. Mastering non-commutativity when combining multiple transformations is the key to avoiding geometric errors that are difficult to debug. The next article in this section is about the Coordinate System — the foundation for understanding which reference system the matrix/vector is being represented in.
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.