Scaling around a specific point in a 2d coordinate system

below is an image of my coordinate system enter image description here

what I'm trying to do is that I want to start scaling around a specific point in the canvas, scaling works fine, but my problem is that I don’t know how to calculate how much to move the canvas when scaling, please note that I don’t use canvas.scale, I just increase the distance between every 2 units in the system when scaling and it works just fine.) there is also some kind of equation that can help me find out how much canvas can be compensated while scaling in opre Jelenia point?

Suppose I want to scale around a point (0.4), how do I know how much to move the canvas when scaling?

+4
source share
2 answers

Equations in this case are less useful than knowing the correct principle. The answer is only one sentence, but first I will need to explain the principle.

When you say “scale around a point”, what you are looking for is to temporarily treat this other point as an origin. Scaling around the beginning is trivial; it is just scalar multiplication. Scaling around another point - three operations:

  • Move the selected point to the origin
  • Scaling in (temporary, new) origin.
  • Pull back so that the origin returns to the designated point.

S. , . , , T, T -1. , " ", T -1 ST. ( .)

T -1 ST S T. . S T ( ), .

, : .

, , - , .

+6

, , , (x0, y0). , s, (u, v). ,

(x',y') = s (x,y) + (u,v)

(x0, y0) ,

(x0,y0) = s * (x0,y0) + (u,v)

(u,v) = (1 - s) (x0, y0)

psudocode

double s= scale_factor;
double x0 = center_point_x;
double y0 = center_point_y;
canvas.scale(s);
double u = (1-s) * x0;
double v = (1-s) * y0;
canvas.translate(u,v);
+3

Source: https://habr.com/ru/post/1648299/


All Articles