PIXELBANKv8.2.1
Menu

Homogeneous Coordinates

MediumGeometry

Implement a conversion between Cartesian coordinates and homogeneous coordinates, a fundamental concept in projective geometry. This conversion is crucial in computer vision for representing and applying projective transformations.

In Cartesian coordinates, a 2D point is represented as (x,y)(x, y). In contrast, homogeneous coordinates introduce an additional dimension, representing the same point as (x,y,1)(x, y, 1). This extension enables the use of linear algebra techniques, such as matrix multiplications, to perform projective transformations.

Here are the steps to convert between these coordinate systems:

  1. To convert from Cartesian to homogeneous, append a third coordinate with value 11.
  2. To convert from homogeneous to Cartesian, divide the first two coordinates by the third.
(x,y)(x,y,1)(X,Y,W)(XW,YW)\begin{aligned} (x, y) &\rightarrow (x, y, 1) \\ (X, Y, W) &\rightarrow \left(\frac{X}{W}, \frac{Y}{W}\right) \end{aligned}

This technique is widely used in image processing and computer vision applications.

Example:

Input:
to_cartesian([6, 8, 2])
Output:
[3.0, 4.0]
Reasoning:

6/2 = 3, 8/2 = 4

Constraints:

  • For to_homogeneous: input is [x, y], output is [x, y, 1]
  • For to_cartesian: input is [X, Y, W], output is [X/W, Y/W] rounded to 4 decimals
  • W is guaranteed to be non-zero
Editor

Test Results

0/0
Run code to see test results.