I have two 2D spaces which are related one to other by a transformation matrix - 3*3 homography matrix for homogeneous coordinates: The first space is "map" and the second one is "camera view" (of camera that is flying above the map in unknown position). Both spaces are restricted either by map boundaries or size of the camera view (both rectangles). I have defined both in camera view and in map some polygons.

I need to display polygons from camera view in map, and vice versa.


Thing gets complicated when a line of a polygon in camera view passes horizon of the ground, and it will get projected to map incorrectly, as a point on the line that lies on the horizon is projected to infinity in map space. The same problem happens if a line of a polygon in the map space crosses the plane that is parallel to camera's projection plane passing through camera's origin.

Therefore, I need to deploy clipping of polygons before the transformation. However, all the literature I found on the topic deals with 3D space and known camera position.


Is there a way to clip a 2D line for 2D projection described by perspective 3*3 homography matrix (ergo, translation, rotation, projection, in homogeneous coordinates)? Is there a way to do this for general 3*3 homography matrix?


Here's the solution I have eventually employed:

Assume that there are spaces A and B, which are related by homography (mapping stuff from A to B): $$ H = \begin{bmatrix} h_{11} & h_{12} & h_{13}\\ h_{21} & h_{22} & h_{23}\\ h_{31} & h_{32} & h_{33}\\ \end{bmatrix}\quad. $$ As $H$ is general homography, some of the points in A may lay in subspace of A that $H$ maps to infinity in B. To identify such points, we have to see how the transformation in homogeneous coordinates works: $$ \begin{bmatrix} x_b\\ y_b\\ w_b\\ \end{bmatrix}=H \begin{bmatrix} x_a\\ y_a\\ 1 \end{bmatrix}\quad. $$ The "dehomogenisation" of coordinates is done by dividing $x_b$ and $y_b$ by $w_b$. Therefore, if we seek for points on horizon in A (which are in infinity in B), $w_b$ must be zero. From principle of matrix multiplication, we get that: $$ w_b = x_a h_{31} + y_a h_{32} + h_{33} = 0 $$

Which is actually a line in A. If $h_{31} = 0$ and $h_{32} = 0$, the line (and the horizon) does not exist and transformation is affine. Otherwise, the line divides space A in two half-planes. One half-plane is above the horizon, and the second one is under the horizon.

The caveat is that we do not know which half-plane is which. To tackle this, I decided to just pick a reasonable point that I believe is under horizon, and check on which half-plane it resides. Such plane I consider to be under horizon.

Furthermore, to tackle the transform of polygons, we can clip them by horizon. The problem is that we cannot clip them directly by the horizon, because resulting points may still lay at infinity. Therefore, we clip them by line parallel to horizon that is reasonable close to it. This approach is very similar to frustum clipping in 3D (near-/far-clipping plane).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.