A
A
andreyk62013-12-08 20:37:40
Programming
andreyk6, 2013-12-08 20:37:40

Projective transformation (search for the relative position of a point)

Good afternoon.
I am now trying to figure out this problem:
Given: a regular quadrilateral and a square, which are given by their coordinates A(x1,y1), B(x2,y2), C(x3,y3), D(x4,y4) and M(0 ,0), N(1,0), P(1,1), K(0,1), respectively.
There is a point P(x,y) that is in this quadrilateral.
Required: Build a projective transformation matrix to transform ABCD into a square MNPK. Next, you need to find the position of the point P`(x`,y`) in the square.
I figured out the construction of the matrix (most likely, I'm doing it right):
I derived the formulas for finding the transformation matrix from a square to a quadrilateral:
6a8d502427c22677c2cbf53731248457.gif.
e5c811cfd439af2380044c9112bb8f30.gif.
2a0656940979f555dff0e84dea452ec5.gif.
0517656cc29a1b8abf456c87816a9e4e.gif.
52619d129b54fbb63edc5750967c6e55.gif.
f614aa91233c94a451c161a09ea9b664.gif.
8af11e05fb439ce03f63db0aa061cc60.gif.
8eada95d6ff3641adc9ab4115201d662.gif.
96cd6d1199b367c0c3eaadeea6601e79.gif.
I get the matrix:
dbdedda97087296721499a40e688944f.gif
After that, thanks to Habrauser @Mrrl , I find the inverse matrix (by the Gauss method).
25979f19d8af6fa1353996d20a132716.gif
Next, I'm trying to get the coordinates of a point in a square given the coordinates of a point in a quad:
44f4619aa89ce688f6157b8d94b82439.gif.
89bf58b2750dd86a87a27fb8a0454b90.gif
But I'm getting the wrong answer. I substitute completely different points, but I get x and y 0.5.
I am sure that the algorithm for finding the inverse matrix works correctly (I checked the results with online services).
I am also confident in the construction of the matrix, substituting a specific x1, y1, x2, y2, x3, y3, x4, y4 and solving the system, I received the same answers on the sheet and in the program.
Where did I go wrong? What am I doing wrong?
You can't do without a fresh look
.
Example:
Given:
A (CP[1]) {x=0 y=0 }
B (CP[2]) {x=1 y=0 }
C (CP[3]) {x=2 y=2 }
D (CP[4]) {x=0 y=1 }
Direct matrix:
{0.666666666666666674 , 0.00000000000000000, -0.33333333333333331}
{0.00000000000000000, 0.66666666666666663, -0.33333333333333337}
{0.00000000000000000, 0.00000000000000000, 1.0000000000000000}
The inverse matrix:
{1.4999999999999998, 0.00000000000000000, 0.49999999999999994}
{-0.00000000000000000, 1.5000000000000000, 0.50000000000000011}
{-0.00000000000000000, -0.00000000000000000, 1.0000000000000000}
thank you all , everything worked correctly.
The problem was in the processing of the received data.
There was a typo when accessing the array, and the Points[i+2] element was taken, but Points[i*2] is needed.
Moral: No need to write code at night)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mrrl, 2013-12-08
@andreyk6

And can you write the obtained direct and inverse matrices for some example? For example, for A=M, B=N, D=K, C=(2,2) ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question