Define a new coordinate system with two rectangular sides as unit vectors and transform the coordinate of the point into a new coordinate system. If both coordinates are between 0 and 1, inside.
In the equations (if A, B, C, D are the angles of the rectangle, P is the point, _x and _y are the components of x and y):
P_x = A_x + x * (B_x - A_x) + y * (D_x - A_x) P_y = A_y + x * (B_y - A_y) + y * (D_y - A_y)
Solve for x and y and check if they are between 0 and 1
Written as a linear system of equations (A, B, C, D, P are vectors of length 2):
[ | ] [x] [ ] [BA | DA] * [ ] = [PA] [ | ] [y] [ ]
The solution is easy, as it has only two dimensions, and you can be sure that you are not the only ones.
groovingandi
source share