So, I have a rectangle divided into two triangles and I have a point:
I know the coordinates of the four vertices of the rectangle (A, B, C and D) and I know the coordinates of P. What I need to know is in which of the two triangles is the point.
I think it's a really simple thing to do, but apparently I can't figure it out by myself.
Any help?
There are couple of ways to tackle this. But the easiest and most straight forward is to check for the slope.
For your example, if slope AP
is lesser than slope AD
then point P
is above the AD
line and vice versa. If the slope is the same, then it is on the same line.
Edit:
Assume the following
A -> (0,3)
B -> (3,3)
C -> (0,0)
D -> (3,0)
Then the slope AD
is (3-0)/(3-0) = 1
. Assume that P
is at (2,2)
, then slope AP
is (2-3)/(2-0) = -1/2
.
We have AD
> AP
, thus point P
must be above the line AD
. Notice that point P
needs to cross AD
in order to be below the line, and thus the slope changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With