View Full Version : Scaling around a fixed point

04-26-2009, 04:51 PM
Just doing some revision for computer graphics and have a mathematical question.
Scale the line p1p2 around the centre of the line.

Scaling factor = [0.4, 0.6]

Around the origina is easy, just a case of
p1'=[10*0.4 OVER 20*0.6] = [4 OVER 12]
p2'=[100*0.4 OVER 150*0.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.

04-27-2009, 03:39 AM
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:

| |
| |

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 :P

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.

04-28-2009, 10:58 AM
Nordic, i think the center point is

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