To start, determine the relative positions of your point within the rectangle:
posXRel = (O.x - A.x) / (B.x - A.x);
posYRel = (O.y - A.y) / (B.y - A.y);
Locate the position of these relative coordinates on the sides of your quadrilateral A’B’C’D’
On A’B’:
posAB.x = A’.x + posXRel * (B’.x - A’.x);
posAB.y = A’.y + posXRel * (B’.y - A’.y);
On B’C’:
posBC.x = B’.x + posYRel * (C’.x - B’.x);
posBC.y = B’.y + posYRel * (C’.y - B’.y);
On C’D’:
posCD.x = C’.x + posXRel * (D’.x - C’.x);
posCD.y = C’.y + posXRel * (D’.y - C’.y);
On D’A:
posDA.x = D’.x + posYRel * (A’.x - D’.x);
posDA.y = D’.y + posYRel * (A’.y - D’.y);
Next step is to find the intersection between the line going from posAB to posCD and the line going from posBC to posDA:
To do this, we need to set the equation:
Y = aX + b for both lines and calculate a and b.
For the line from posAB to posCD:
a1 = (posAB.y - posCD.y) / (posAB.x - posCD.x);
b1 = posAB.y - a1 * posAB.x;
For the line from posBC to posDA:
a2 = (posBC.y - posDA.y) / (posBC.x - posDA.x);
b2 = posBC.y - a2 * posBC.x;
Finally, we are searching for the solution of the equation:
a1 * O’.x + b1 = a2 * O’.x + b2;
Therefore, the new coordinates will be:
O’.x = (b2 - b1) / (a1 - a2);
O’.y = a1 * O’.x + b1;
Could you confirm if this method is successful?