Translating and scaling a line based on two grabbed points

1.3k Views Asked by At

Say there is a line segment going from 0 to 10, now imagine that point 7 and 8 are 'grabbed' and translated to respectively 6 and 11. The effect would this would be that the line segment get's scaled and translated. How can I determine the new defining points of the new line segment.

Line scaling and translation

Please note, in the above image there is only a x axis, no y axis.

I believe this problem should be quite simple, but after trying out different things nothing seems to work. I suppose that I should calculate the scale $s = \frac{g_{1start}-g_{2start}}{g_{1end}-g_{2end}}$ and multiply that with $x_{1start}$ and $x_{2start}$ or something along those lines, but I just can't figure out how to approach this problem correctly (rather than guessing randomly).

1

There are 1 best solutions below

0
On BEST ANSWER

Let

$$x_{new} = h_1 + (x - g_1) \frac{h_2 - h_1}{g_2 - g_1}.$$

where I've used $g_i$ for your starting points (7, 8) and $h_i$ for your ending points (6, 11). The formula shows how to take a point $x$ in the pre-stretch coordinates and tell its post-stretch coordinates. So

$$x_1^{end} = h_1 + (x_1^{start} - g_1) \frac{h_2 - h_1}{g_2 - g_1},$$

for instance, tells you how to transform the left end.