Transform Point World to Camera
Transform a 3D point from world coordinates to camera coordinates.
The transformation from world to camera frame uses a rotation matrix R and translation vector t:
Xcam​=R⋅Xworld​+t
where:
- Xworld​ is the point in world coordinates
- R is the 3×3 rotation matrix (camera orientation)
- t is the translation vector (camera position)
- Xcam​ is the point in camera coordinates
This is a rigid transformation - it preserves distances and angles. The camera "looks down" its Z-axis, with X pointing right and Y pointing down (typical convention).
Example:
transform_point([[1,0,0],[0,1,0],[0,0,1]], [1, 2, 3], [0, 0, 0])
[1, 2, 3]
With identity rotation and translation [1,2,3]:
- X_cam = I × [0,0,0] + [1,2,3]
- = [0,0,0] + [1,2,3]
- = [1,2,3]
- When R is identity and point is origin, result equals t.
Constraints:
- R: 3x3 rotation matrix
- t: translation vector [tx, ty, tz]
- point: [X, Y, Z] in world coordinates
- Return transformed point [X', Y', Z'] in camera coordinates
More from CV: Structure from Motion and SLAM
Background Knowledge
Coordinate Systems and Rigid Transformations
In computer vision, objects exist in multiple coordinate systems. The world coordinate system is a fixed reference frame in the scene (often defined by the problem or calibration markers), while the camera coordinate system is centered at the camera's optical center with axes aligned to the camera's orientation. A rigid transformation—consisting of rotation and translation—maps points between these frames without distorting distances or angles. This is fundamental to 3D reconstruction, pose estimation, and any multi-view geometry problem where you need to understand how cameras observe the same scene from different positions.
Rotation Matrices and Translation Vectors
The rotation matrix R is a 3×3 orthogonal matrix (where RTR=I) that encodes the camera's orientation relative to the world frame. Each column of R represents where the world's basis vectors point in the camera frame. The translation vector t (3×1) represents the camera's position in world coordinates, but in the transformation equation, it's applied after rotation to shift points into the camera's local frame. Understanding that t is not simply the camera's world position (that would be −RTt) is crucial—the formula given applies the rotation first, then translates.
Camera Coordinate Convention
Cameras typically use a convention where the Z-axis points forward (into the scene), X points right, and Y points down. This differs from some mathematical conventions and affects how you interpret the resulting coordinates. Points with positive Z are in front of the camera and will project onto the image plane; negative Z points are behind the camera.
Algorithm/Approach
The transformation is a straightforward affine transformation applied in sequence:
- Rotate the world point using the rotation matrix
- Translate the rotated point by adding the translation vector
This can be expressed as a single matrix operation if you use homogeneous coordinates, but the basic approach is linear algebra: matrix-vector multiplication followed by vector addition.
Step-by-Step Strategy
Continue the full explanation
You're reading the free preview. Unlock the complete walkthrough, the code editor, test runner and reference solution with Premium.
Editor locked
The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.