How to determine if a point is within a quadrilateral

slykat picture slykat · May 7, 2011 · Viewed 19.9k times · Source

Goal

I want to determine if a test point is within a defined quadrilateral. I'm probably going to implement the solution in Matlab so I only need pseudo-code.

Inputs

Corners of quadrilateral : (x1,y1) (x2,y2) (x3,y3) (x4,y4)

Test point : (xt, yt)

Output

1 - If within quadrilateral

0 - Otherwise

Update

It was pointed out that identifying the vertices of the quadrilateral is not enough to uniquely identify it. You can assume that the order of the points determines the sides of the quadrilateral (point 1 connects 2, 2 connects to 3, 3 connects to 4, 4 connects to 1)

Answer

mili picture mili · Apr 28, 2013

enter image description here

You can test the Point with this condition. Also you can treat quadrilateral as 2 triangles to calculate its area.