Two-dimensional perspective projection transformation

Source: Internet
Author: User

As shown in the figure below, the unit square in the XY plane is projected onto any plane p and becomes an irregular quadrilateral abcd, and we can calculate the coordinates (x ', y ') after the projection of any point on the plane xy to the plane p by the coordinates before and after the four vertices of the square.


We notice that the four sides of the square are projected to the plane P, respectively, to the line Ab,bc,cd,da, that is, the projection is located in a straight line point, the projection is still in a straight line, for the straight line, the transformation is linear, but the projection of the two parallel lines, the projection is no longer parallel, For a plane, this transformation is not linear. However, although this transformation cannot be represented as a linear transformation, it can be represented as two linear transformations, so there is a homogeneous coordinate,


The advantage of homogeneous coordinates is that the projection transformation can be transformed into a linear transformation, thus using matrix operations to solve the problem.

Using homogeneous coordinates, you can have the following transformations


Written in equation:

X ' = Ax + by + Cw

Y ' = Dx + Ey + Fw

W ' = Gx + Hy + Iw


where (X,Y,W) is the coordinate before the transformation, (x ', y ', W ') is the transformed coordinate, (A B C ...) is the transformation matrix


According to the above discussion, we know that the Quadrilateral four vertex transformation before and after the two-dimensional coordinates, each point can write three equations, a total of 12 equations, and the transformation matrix of 9 unknowns, plus the transformation of the coordinates w is also unknown, a total of 13 unknowns, so this equation group has an infinite number of groups of solutions, But on the projection plane, the homogeneous coordinates of each point can have countless expressions, so we can find X, Y, as long as the W rule is 1.


According to affine transformation theory, the coefficient c,f represents the origin displacement (translation transformation) before and after the transformation, in order to simplify the calculation, we assume that the c,f is equal to 0 (that is, there is no displacement before and after the transformation), and the coefficient i is adjusted to 1, so there is


where p is the scale factor

Write an equation

PX ' = Ax + by (1)

Py ' = Dx + Ey (2)

p = Gx + Hy + 1 (3)

In the Formula 3 elimination 1 and the formula 2 p, you get 2 equations

Ax + by-gxx '-hyx ' = X ' (4)

Dx + ey-gxy '-Hyy ' = Y ' (5)

We assume that the coordinates of the unit square area consisting of point (0,0) (1,0) (0,1) (four) points are mapped to the target plane, respectively (0,0) (x1 ', y1 ') (x2 ', y2 ') (X3 ', Y3 '), and the origin (0,0) mapping to (0,0) is not in the computed column. Put the other three points into the formula (4), the formula (5), the total six equations
A-gx1 ' = X1 ' (6) b-hx2 ' = X2 ' (7) A + b-gx3 '-Hx3 '                               = X3 ' (8) d-gy1 ' = Y1 ' (9) e-hy2 ' = Y2 ' (+) D + e-gy3 '-Hy3 ' = Y3 ' (11)
Bashi (6) (7) (10) (11) transform, get A = X1 ' + Gx1 ' (+) B = X2 ' + Hx2 ' (D = y1) ' + Gy1 ' (+) E = y2 ' + Hy2 ' (15)
Then substituting (8) (11), get X1 ' + Gx1 ' + x2 ' + Hx2 '-Gx3 '-Hx3 ' = x3 ' y1 ' + Gx1 ' + y2 ' + Hy2 '-Gy3 '-Hy3 ' = Y3 '


After finishing for G (X3 '-X1 ') + H (X3 '-x2 ') = X1 '-(x3 '-X2 ') g (y3 '-y1 ') + H (y3 '-y2 ') = Y1 '-(y3 '-y2 ')

Make dx31 = x3 '-X1 ' dx32 = x3 '-y2 ' dy31 = Y3 '-y1 ' dy32 = Y3 '-y2 '

Starting from the following, it is easy to write, removing the apostrophe after X, y

dx31g + dx32h = x1-dx32 dy31g + dy32h = y1-dy32
Solve this equation
Coefficient Matrix M =
Dx31 dx32 dy31 dy32
Det (M) = dx31dy32-dy31dx32
Inverse Matrix M-1 = 1/det (M) *
Dy32-dx32-dy31 dx31
So G * DET (M) = Dy32 * (x1-dx32)-dx32 * (Y1-DY32) = x1 * dy32-dx32 * dy32-y 1 * dx32 + dx32 * dy32 = x1 * Dy32-y1 * dx32
H * DET (M) =-dy31 * (x1-dx32) + dx31 * (y1-dy32) Note x1-dx32 = x2-dx31, y1-dy32 = x2-dy31, so H * DET (M) =-dy31 * (x2-dx31) + dx31 * (y2-dy31) =-x2*dy31 + dy31*dx31 + y2*dx 31-dx31*dy31 = y2*dx31-x2 * dy31

Substituting G,h (12) (13) (14) (15) can be calculated a,b,c,d A = x1 * (1 + G) B = x2 * (1 + H) D = y1 * (1 + G) E = y2 * (1 + H)
In this way, all coefficients of the transformation matrix are obtained.















Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.