# Scaling points based on a given origin.

im trying to solve the following problem but cannot find any solution on my own. Take the following example. I have two points A and B. They have the following coordinates:

Ax = -100
Ay = 0
Bx = 100
By = 0


Now I would like to scale my points by factor x in the coordinate system based on a given point as origin. This point has the same coordinates as point A:

Px = -100
Py = 0
X = 2


I found the following formula to calculate the resulting coordinates:

Ax' = X * (Ax - Px) + Px
Ay' = X * (Ay - Py) + Py


With this formula I can increase X as long as I scale from the same point P. But how can I solve this problem if P also changes while X increases? Thank you in advance. And sorry im not the best in math so I dont know if I choosed the right Tag for this topic.

As requested here is a little example to make myself clearer. Imagine 2 Points A and B with the following coordinates:

A(-100, 0)
B(100, 0)


Now I set my origin for scaling to the positon of point one and zoom by a factor of two:

P(-100, 0)
X = 2


When I appliy the equation above I expect point A to remain at its position and point B moving to postion (300,0).

Ax' = 2 * (-100 + 100) - 100 = -100
Bx' = 2 * (100 + 100) - 100 = 300


As you can see this works. Now I move my point for scaling to the position of the scaled B and increase X to 3:

B(300,0)
P(300,0)
X = 3
Bx' = 3 * (300 - 300) + 300 = 300


As you can see this works too. But my problem is that I cant change the initial coordinates of B (because I am writing a computer program and my coordinates should not change) and taking this into account the equation does not work:

B(100,0)
P(300,0)
X = 3
Bx' = 3 * (100 - 300) + 300 != 300


Is it possible to calculate the final coordinates of B without changing its initial coordinates?

Solved

Ok,

I solved my problem by moving and scaling my coordinates system instead. This way my points could keep their original coordinates. Thanks for your answers.

• How does $P$ change as $X$ increases? Commented Nov 11, 2012 at 1:18
• For example on the first calcualation I have P(-100,0) and X=2 and on the second calculation I have P(100,0) and X=3 But the second should take the changes from the first one into account. Commented Nov 11, 2012 at 1:25
• Why would something change? I don't see any problem with the equations.
– tst
Commented Nov 11, 2012 at 1:34
• The reason is that I am writing a software at the moment and i would like to zoom into my content. Zooming should be based on the mouse position. This means the mouse position is my origin for scaling. It works fine with the equation above all my points are moving as intended as long I dont move the mouse to a different location and zoom further. Commented Nov 11, 2012 at 1:43
• Why don't you just change P based on where your mouse is every time you move it and do the scalings one by one? You can get the coordinates of the mouse position, cannot you? In other words, can you tell exactly what you are doing and what exactly doesn't work? Commented Nov 11, 2012 at 2:22

It sounds like you want to zoom in based on an origin at $P$ by a factor $X$. The new point $P'=(0,0)$ because it is the origin. Given a point $A$, $Ax'=X(Ax-Px), Ay'=X(Ay-Py)$ in the new system, because you want to scale the distance from $P$ by a factor of $X$.