0

I have a geometrical question, but if need be I mention that I use Qt so I can do some cool geometric stuff if needed, like QPolygon::intersected(QPolygon)

We are on the 2D plane. Start from a base rectangle. Choose two corners, and for each corner, choose a (different) direction of the plane. Move said corners back and forth along this direction by some given magnitudes and obtain 4 new points.

Note 1 : the corners will have been chosen such that, given the direction along which they will be translated, they will never end up inside the base rectangle.

Create a minimal extended rectangle that captures those 4 new points plus the existing base rectangle.

As per note 1, the minimal extended rectangle always contains the base rectangle.

Also, truncate the parts that are "outside" the two infinite lines created by choosing 2 directions on the plane and 2 corners, which I will call truncation lines.

As per note 1, the truncation lines will always intersect outside the BASE rectangle (but not necessarily outside the minimal extended rectangle)

How to quickly compute the polygon obtained, in all cases ?

In all the following pictures :

The base rectangle is red. For each chosen corner, a double arrow shows the orientation of the corner translation in either chosen direction. The green rectangle is the minimal extended rectangle that encompasses the base one plus the points obtained by corner translations. The green area is the polygon after cutting out using the two vectors, which I want to compute.

Here some perfect examples :

enter image description here

enter image description here

The final polygon has 6 vertices.

But of course things can get messy :

enter image description here

Here the truncation lines intersect inside the extended minimal rectangle. The final polygon only has 5 vertices.

Or messier :

enter image description here

Here the truncation lines intersect inside the extended minimal rectangle and in fact within one of the translation vectors. The final polygon has 4 vertices

One idea is to create a polygon using points "far out" on the truncation lines, and ask for Qt to intersect that with the minimal extended rectangle.

I have access to the points, and as far as order there is one more note I need to make : the arrows formed by the pairs of points obtained by back-and-forth translation are such that, if taken to go from the hollow to the plain, the arrows will always rotate clockwise around the base rectangle. You will see this was the case in all my drawings. Programmatically, I have access to each translated points (hollow blue, hollow purple, plain blue, plain purple).

The suggested polygon will be in orange.

This works in that case :

enter image description here

But fails in that one :

enter image description here

The red area is wrong. It is outside of both truncation lines, instead of inside of both. Plus this requires to go very far along the truncation lines, and I'm not sure my environment will not explode at some point.

Any other suggestions ?

Slides here for copying and drawing some more

Charles
  • 988
  • 1
  • 11
  • 28

0 Answers0