-1

We have a need to re-size 2D polygons in either X or Y-axis using c++. I did some search and read that re-sizing in one direction will lead to unpredictable results and is not feasible. I understand that may apply to non-manhattan polygons (polygon with non-90 edges). But will there be a problem resizing manhattan polygons or paths in one dimension? For e.g., if it is simple rectangle, I should be able to increase either width or height. In case of manhattan polygons or paths, can we break it into rectangles and re-size each of them in one dimension?

I have looked at Boost polygon and Clipper and I do not see any API to resize polygons in either X or Y only. Is there any software that supports this or any pointers to implement this is appreciated?

cppcoder
  • 1,194
  • 4
  • 16
  • 30
  • "I did some search and read that re-sizing in one direction will lead to unpredictable results and is not feasible." -- Could you provide a link? That's a rather odd conclusion. – Rethunk Mar 03 '16 at 05:46
  • 1
    Unless we don't have the same understanding of "resizing", there is absolutely no problem. More generally, you can apply any affine transform (X = ax+by+c, Y= dx+ey+f) to the vertices. –  Mar 03 '16 at 09:06
  • Thanks @Yves for the comment. This is what I want to do. Can you provide it as an answer and I will accept it. If you are aware of any packages which provide this kind of functionality in C++, please add it to the answer. – cppcoder Mar 07 '16 at 23:20
  • I would never use a package for an operation that takes four lines of code, braces included. –  Mar 07 '16 at 23:25
  • 1
    @Yves, Thanks for your prompt response. I looked into affine transformation, it supports Translation, shear, scale, rotation and combination of these operations. I'm not sure it serves my purpose. For e.g. if I have a unit square as polygon with Lower-Left=(0,0) - Top-Right=(1,1), when I resize in X by 1 unit, the new polygon should have LL=(-1,0) & TR=(2,1). I don't see a way to derive this using affine transformation. – cppcoder Mar 08 '16 at 00:39
  • 1D scaling is a trivial instance of the affine transform. –  Mar 08 '16 at 08:05
  • @Yves, I do not want to do scaling. only buffering as explained here: http://stackoverflow.com/questions/1109536/an-algorithm-for-inflating-deflating-offsetting-buffering-polygons. The difference is, the increase needs to be in one dimension only either x or y, by adding a pre-defined number. Can you elaborate on how this can be done using affine transformation? thanks for your response. – cppcoder Mar 08 '16 at 17:40

1 Answers1

1

Usually, a polygon is represented by a list of vertices. In order to resize them, you should be able to multiply or divide their x and y values by any scaling factor (2x, 1/2, 5x) in either dimension. Afterwards, depending on your renderer, you may need to clamp the scaled x and y values to whole numbers.

The renderer will probably handle aliasing for you so your only concern is multiplying x or y values by your scaling factor. Many graphics engines allow access to a polygon's vertices, which you should be able to multiply just fine.

Aaron3468
  • 1,734
  • 16
  • 29