Search code examples
vectorlinescaleshapes

Scalling connected lines


I have some kind of a shape consisting of vertical, horizontal and diagonal lines. I have starting X,Y and ending X,Y (this is my input - just 2 points defining a line) of each line and I would like to make the whole shape scalable (just by changing the value of a scale ratio variable), so that I can still preserve the proper connection of the lines and the proportions as well. Just for getting a better idea of what I mean: it'd be as if I had the same lines in a vector editor.

Would that be possible with an algorithm, and could you please, give me another possible solution if there is no such algorithm ?

Thank you very much in advance!


Solution

  • what point do you want it to scale about? You could scale relative to the first point, the center, or some other arbitrary location. Typically, you subtract out an offset (for instance the first point in your input), multiply by a scale factor, and then add back the offset.

    A more systematic approach in computer graphics would be to use a transformation matrix... although thats probably overkill in your case.