Scaling vectors from a central point?

I am trying to find out if I have points that make, for example, a square:

* * * * 

and Iโ€™ll say that I know the center of this square. I want a formula that will make her double her size, but from the center

  * * * * * * * * 

Therefore, the new shape is twice as large from the center of the polygon. It should work for any shape, not just squares.

I'm more looking for more theory than implementation.

+4
source share
4 answers

If you know the center point cp and the point v in the polygon that you want to scale on scale , then:

 v2 = v - cp; // get a vector to v relative to the centerpoint v2_scaled = v2 * scale; // scale the cp-relative-vector v1_scaled = v2_scaled + cp; // translate the scaled vector back 

This translation-scaling template can be performed on vectors of any dimension.

+7
source

If you want the shape to be twice as large, reduce the coordinate distance to sqrt(2) times further from the center.

In other words, suppose your point is at (x, y) and the center is (xcent, ycent) . Your new item should be in

 (xcent + sqrt(2)*(x - xcent), ycent + sqrt(2)*(y - ycent)) 

This will reduce the distance from the new "source", (xcent, ycent) so that the area doubles. (Because sqrt(2)*sqrt(2) == 2) .

0
source

I'm not sure there is a clean way to do this for all types of objects. For relatively simple ones, you should be able to find the "center" as the average of all the X and Y values โ€‹โ€‹of the individual points. To double the size, you will find the length and angle of the vector from the center to the point. Double the length of the vector and keep the same angle to get a new point.

Editing: Of course, โ€œtwice the sizeโ€ is open to several interpretations (for example, doubling the perimeter compared to doubling the area). They would change the multiplier used above, but the basic algorithm would remain essentially the same.

0
source

To do what you need, you need to perform three operations: translate the square so that its centroid coincides with the origin, scale the resulting square, translate it back.

0
source

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


All Articles