Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inverse 3D (triangle) projection

I have a 3D math problem which I just can't seem to solve.

I have data of 3 points. The data is a (2D) coordinate on a plane, floating somewhere in 3D space. I also know the (2D) coordinate of the projection. That results in the following array of data:

[[[x1,y1], [px1,py1],
 [[x2,y2], [px2,py2],
 [[x3,y3], [px3,py3]]

Where the normal (x1 etc.) coordinates stand for the coordinates on the plane and the other (px1 etc.) for the projected coordinates.

What I would like to do is project a new 2D coordinate ([x4,y4]).

.

What I tried so far:

Ofcourse you need an eye for projection, so I set that to [xe,ye,-1]. The xe and ye are known. (It is photo referencing, so I just placed the eye in the center of the photograph.)

Beneath the eye I placed the projection surface (z=0). That gives the following projection coordinates:

[[[x1,y1], [px1,py1,0],
 [[x2,y2], [px2,py2,0],
 [[x3,y3], [px3,py3,0]]

I can't do the same for the coordinates on the plane, since I don't know anything about that plane.

I also figured that I could make a parameterized formula of the lines running from the eye through the projection coordinates. For line1 that would be:

line1x = xe+(px1-xe)*t1
line1y = ye+(py1-ye)*t1
line1z = -1+t1 // = -1+(0--1)*t1

I also know the distance between the points in 3D. That's the same as in 2D. That means the distance between point1 and point2 would be sqrt((x1-x2)^2+(y1-y2)^2).

I also know the distance between the lines (line1 and line2) at any time. That is sqrt((line1x-line2x)^2+(line1y-line2y)^2+(line1z-line2z)^2).

However, I don't really know how to go from here... Or even whether this is the right route to take.

.

I hope you understand what I want to be able to do, and that you can help me.

Thanks in advance!

like image 929
Pieter Jongsma Avatar asked Oct 15 '22 15:10

Pieter Jongsma


1 Answers

There is a function Projection, which can transform points so that Projection([x1, y1]) = [px1, py1] , Projection([x2, y2]) = [px2, py2], Projection([x3, y3]) = [px3, py3]. If I understand correctly, author wants to know how to find this Projection function, so that he can trasnform [x4, y4] into [px4, py4].

Since we are dealing with planes here, the Projection function looks like this:

Proj([ix, iy]) :
    return [ax*ix + bx*iy + cx,
            ay*iy + by*iy + cy];

Using that we can make 2 equation systems to solve.

The first one
x1 * ax + y1 * bx + cx = px1
x2 * ax + y2 * bx + cx = px2
x3 * ax + y3 * bx + cx = px3

Solving for ax, bx and cx gives us

ax = (px1 * (y3 - y2) - px2*y3 + px3*y2 + (px2 - px3) * y1) /
     (x1 * (y3 - y2) - x2*y3 + x3*y2 + (x2 - x3) * y1)
bx = - (px1 * (x3 - x2) - px2*x3 + px3*x2 + (px2 - px3) * x1) /
     (x1 * (y3 - y2) - x2*y3 + x3*y2 + (x2 - x3) * y1)
cx = (px1 * (x3*y2 - x2*y3) + x1 * (px2*y3 - px3*y2) + (px3*x2 - px2*x3) * y1) /
     (x1 * (y3 - y2) - x2*y3 + x3*y2 + (x2 - x3) * y1)

The second one x1 * ay + y1 * by + cy = py1
x2 * ay + y2 * by + cy = py2
x3 * ay + y3 * by + cy = py3

Solving for ay, by and cy gives us

ay = (py1 * (y3 - y2) - py2*y3 + py3*y2 + (py2 - py3) * y1) /
     (x1 * (y3 - y2) - x2*y3 + x3*y2 + (x2 - x3) * y1)
by = - (py1 * (x3 - x2) - py2*x3 + py3*x2 + (py2 - py3) * x1) /
     (x1 * (y3 - y2) - x2*y3 + x3*y2 + (x2 - x3) * y1)
cy = (py1 * (x3*y2 - x2*y3) + x1 * (py2*y3 - py3*y2) + (py3*x2 - py2*x3) * y1) /
     (x1 * (y3 - y2) - x2*y3 + x3*y2 + (x2 - x3) * y1)

Note: I used this tool to solve equation systems.

like image 100
Juozas Kontvainis Avatar answered Oct 19 '22 00:10

Juozas Kontvainis