2
$\begingroup$

If I have a random polygon of any complexity, be it a square or an irregular 20 sided polygon, how can I scale this up?

I know the coordinates of each point on the polygon, but that is all.

Another requirement is that as the polygon is scaled up, each side must be an equal distance from its original smaller counterpart. Unlike if you were to directly upscale a rectangle for example, where two sides would be more distant than the other two.

Any help would be greatly appreciated, thanks.

EDIT:

You can see in the demonstration image below, the top rectangles are directly scaled, 1:1. I want to achieve the bottom rectangle scaling, keeping equal distance. How might it be possible to calculate the new x,y coords of the scaled up polygon?

enter image description here

EDIT 2:

I have been corrected, I should be referring to Polygon Offsetting (not scaling!).

$\endgroup$
  • $\begingroup$ Thanks @Minestrone. I've thrown on some more tags, if only my knowledge of mathematical terminology was better! At least I'm learning. $\endgroup$ – Josh Kahane Jan 26 '16 at 22:12
  • $\begingroup$ Do you have a picture of an example of what you have in mind? The bit about the rectangle is making me wonder what your version of a scaled up rectangle would even look like... $\endgroup$ – pjs36 Jan 26 '16 at 22:13
  • $\begingroup$ It sounds like what you want is impossible unless the polygon is regular or otherwise very symmetric. For a generic non-regular polygon (such as a rectangle that's not a square) it will be impossible to place a (non-trivially) scaled version of the polygon such that all sides are displaced by the same distance! $\endgroup$ – Henning Makholm Jan 26 '16 at 22:14
  • $\begingroup$ Hmmm, I understand your point regarding the symmetry. I have added a sample to demonstrate what I mean. $\endgroup$ – Josh Kahane Jan 26 '16 at 22:20
  • $\begingroup$ (Correction -- the criterion for being scalable-with-a-common-displacement is that the polygon has an inscribed circle. It doesn't need to be particularly symmetric for that, though. In particular it is always possible for a triangle). $\endgroup$ – Henning Makholm Jan 26 '16 at 22:20
2
$\begingroup$

This is called polygon offsetting rather than scaling.

In the general case, this is much harder than it seems, as different parts of the inflated polygon can overlap each other, letting holes appear, and some edges may completely disappear. The way to handle corners isn't so well defined either.

For an exact solution, have a look at Clipper.

For a simple solution not guaranteed to work on all shapes, you have to consider all vertices in turn, draw lines parallel to the abutting edges, at the desired distance on the right side, and find their intersection.

enter image description here

$\endgroup$
  • $\begingroup$ Thank you the term clarification Yves. I'm not sure Clipper will work out integrating into my code base, but I'll take a close look. Thanks! $\endgroup$ – Josh Kahane Jan 26 '16 at 22:29
  • $\begingroup$ @JoshKahane: the elementary solution might be enough for your needs. $\endgroup$ – Yves Daoust Jan 26 '16 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.