How to determine if a point is inside a 2D convex polygon?

后端 未结 8 1865
别那么骄傲
别那么骄傲 2020-11-27 12:58

I have a convex polygon (typically just a rotated square), and I know all of 4 points. How do I determine if a given point (yellow/green) is inside the polygon?

8条回答
  •  不知归路
    2020-11-27 13:33

    Say, x[] is the array of x points and y[] is the array of y points.
    You are meant to return 1 if the point exists in the polygon and 2 if not. where (planeX,planeY) is the point you need to check.

    //check like this
    return new Polygon(x,y,x.length).contains(planeX, planeY)?1:2;
    

提交回复
热议问题