views:

32

answers:

1

Hello,

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!

+3  A: 

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.

tbischel
Thanks for the quick reply! Actually, both scaling relative to first point and center would do the job for me.Would you explain the offset thing, please? Can it be the same for all the points?Say I have a triangle with the following coordinates (3 lines: AB, BC, AC):A (1,2), B (4,2) and C (3,4)Could anybody, please, give me a simple pseudo-code for scaling the triangle properly?Thanks,Hristo
Hristo
just subtract the respective X and Y values for each point by those in point A. A' = A-A, B' = B-A, C' = C-A. Then multiply by your scale factor... for instance if you want to double the size... A'' = 2.0*A', B'' = 2.0*B', C'' = 2.0C'... finally add back in your offset. A''' = A''+A, B''' = B''+A, C''' = C''+A
tbischel
Thanks very much! I'll give it a try and then get back to you with the result.
Hristo
Yes, it does the job perfectly! Thanks once again!
Hristo