How to find the original coordinates of a point inside an irregular rectangle? I'm a third year computer science student. I'm working on a project Data-show touch screen In schools classrooms.
I'll try to explain my problem as much as I can.
The project has three main components; A computer, a Data-show and a webcam.
The teacher will plug the data-show in the computer and the computer screen will appear on the wall of the classroom to all students.
The main purpose of the project is to turn the image of the screen displayed on the classroom wall into interactive screen; when the teacher tabs with his finger on an image of a Button displayed on the wall, the webcam that is connected to the computer will capture the position of the teacher's finger and find his (x,y) coordinates for a reference point on the wall, and raise a click event in the related (x,y) position on the screen.
The screen of the computer has two dimensions; Width-&gt;X and Height-&gt;Y. And for every point in the screen such as P, it could be located on the screen using two numbers (Px,Py), where Px is the distance between the point P and the left side of the screen, and Py is the distance between the point P and the top side of the screen. In other words, the reference for all points in the screen is the top left corner of the screen.

The data-show will display an irregular Quadrilateral shape of the screen on the wall. the shapes will not be regular squares or rectangles due to the angle that the teacher puts the data-show in. What I'm asking for are the equations that will calculate the (x,y) point on the screen that represents the (x,y) tapped point on the wall.
There is mainly four shapes the data-show may display on the wall. For each shape of them the only known things are the coordinates of the four angles(corners) of the quadrilateral shape.
1. an optimal rectangle
The displayed image on wall has a very low chance to shape an optimal rectangle, but it's the basic shape that could be formed.

Suppose that the red point P'(Px',Py') represents the coordinates of the place the teacher tapped on with his finger.
To get the original (Px,Py) coordinates from the point (Px',Py') on the wall, I can do the following.

Calculate the width-&gt;X' and the height-&gt;Y' of the displayed image by the law of distance between two points.



find the ratio between X&amp;X', and between Y&amp;Y'. I'll call the first ratio rx and the second ratio ry.



Multiply Px' by rx to get Px, and multiply Py' by ry to get Py.


2. an optimal trapezoidal.

The displayed image on wall could also shape an optimal trapezoidal. I asked some of my friends from the applied mathematics college to help me to find the two equations to find the original coordinates of the point, and they did some calculations and came out with these two equations;
In this shape

To find X:

and to find Y I can use the same way used in the rectangle; finding the ratio between Y and the height of the trapezoidal H.

3. an irregular quadrilateral.
My question is about this shape, the data-show in most times will shape an irregular shape. Imagine this shape like

None of the shape's lines is vertical or horizontal, all lines may have different lengths and they may have different angels from each other.
My question is
I'm searching for equations that will find the original P(x,y) point of the point P'(X',Y'). Things I know are the coordinates of the points P1, P2, P3, P4, P'
What are those equations? and how are they derived?
This is what the concept of a homography was invented for.  You know the coordinates of the four corners on your screen and on the wall, and you want to find a transformation that maps from screen coordinates to wall coordinates.  There will be a homography that maps between the two coordinate systems.  So, your task is: given four points with known mappings, find a homography that is consistent with that.

If you're using OpenCV, see the findHomography() method, as well as warpPerspective().