Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scaling vectors from a center point?

I'm trying to figure out if I have points that make for example a square:

 *     *



 *     *

and let's say I know the center of this square. I want a formula that will make it for eample twice its size but from the center

 *               *

      *     *



      *     *

 *               *

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

I'm looking more for the theory behind it more than the implementation.

like image 381
jmasterx Avatar asked May 06 '10 18:05

jmasterx


1 Answers

If you know the center point cp and a point v in the polygon you would like to scale by 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 translate-scale-translate pattern can be performed on vectors of any dimension.

like image 93
fbrereto Avatar answered Sep 21 '22 12:09

fbrereto