 # Scaling around a fixed point

Just doing some revision for computer graphics and have a mathematical question.
Scale the line p1p2 around the centre of the line.
p1=[10,20]
p2=[100,150]

Scaling factor = [0.4, 0.6]

Around the origina is easy, just a case of
p1’=[100.4 OVER 200.6] = [4 OVER 12]
p2’=[1000.4 OVER 1500.6] = [40 OVER 90]

I just cant work out how to do it around the center of the line. If anyone knows what i am on about, any advise appreciated.
cheers

Correct me if im wrong about your needs, but if you try and visualize the line as a rectangle it becomes easier.

p1 would be the first vertex of the rectangle, and p2 would be the last.

Here is an example of how it could look:

``````
p1------.
|       |
|       |
.------p2

``````

And here is how to get the center point of the line:

``````
center.x = p2.x - p1.x * 0.5f;
center.y = p2.y - p1.y * 0.5f;

``````

Now we have the center point of the line. Lets scale the damn thing ``````
p1.x = center.x + ((p1.x - center.x) * scalingFactor.x);
p1.y = center.y + ((p1.y - center.y) * scalingFactor.y);

p2.x = center.x + ((p2.x - center.x) * scalingFactor.x);
p2.y = center.y + ((p2.y - center.y) * scalingFactor.y);

``````

This is just a sketchy technique. It’s optimizable.
And I never tested it, so there might be some errors somewhere.

Nordic, i think the center point is

``````
center.x = ( p2.x + p1.x ) * 0.5f;
center.y = ( p2.y + p1.y ) * 0.5f;

``````