Determine the quadrant containing most of the 4-gon (polygon)

Problem:

Determine which quadrant contains most of the 4-ron area.

Input: A list of four (x, y) pairs containing the unordered vertices of the polygon. Output: A value that indicates in which of the four quadrants most of the polygon's area falls.

The rectangle will look roughly "rectangular". In particular, it is a rectangle that has been transformed by a 3D projection matrix.

Example: 4-Gon Example

The points are designated as 0, 1, 2, and 3. The axis intersection points are also plotted on the graph. In this case, the answer is the 1st quadrant (top right).

My real solution is to order the points clockwise. Then, to identify the vertices (up to 4) of the polygons created by cutting the larger polygon on the x and y axes. After that, I use the lace formula to calculate the area for each and then return the quadrant with the largest. With all the edge cases, this is a little messy and slower than I'd like. This function is used in the inner loop of the real-time application. Does anyone have something better?

I am using NumPy / Python / etc, but solutions in other languages ​​are welcome.

Thank!

+3


source to share





All Articles