3
$\begingroup$

I'd like to resize a group of n-objects -- either circles or rectangles -- all at once and fit them into the newly resized area with newly calculated x,y coordinates and width/height dimensions. The resizing originates in the CENTER of the resized area. It probably helps with some visuals, so please take a quick look at this video:

http://screencast.com/t/AEuJzTS51vja

And here is an image where I'm trying to distill the question as simply as I can. Based on the resizing from the center, I need to know how to calculate the new coordinates and dimensions for "A" "B" and "C" below -- I've given the dimensions of the bounding box, both in its original form, and its resized form.

(I know the x,y width/height of "A" "B" and "C" in the orig box -- they're just not labeled, but you can assume that they're known values)

How do I calculate the new sizes of the objects in the new bounding box?

  • 0
    the origin is the upper-left of a scrollable canvas -- so the x,y coordinates of the orig box could feasibly be any random x,y coordinates, up to 50000,50000 in this example. not sure if that helps.2012-02-14

2 Answers 2

5

If the center of resizing (which it sounds like is the center of your outer rectangle—the one point that is not moved by the resizing) is $(x_c,y_c)$ and you're resizing by a factor of $r_x$ in the $x$-direction ($r_x=\frac{83}{185}$ in your example) and $r_y$ in the $y$-direction ($r_y=\frac{330}{185}$ in your example), then $(x_\text{new},y_\text{new})=(x_c+r_x(x_\text{old}-x_c),y_c+r_y(y_\text{old}-y_c)).$

  • 0
    https://math.stackexchange.com/questions/2342310/scale-group-of-objects2017-06-30
1

Because you resized the box's y-scale from $185$ to $330$ pixels - a ratio of $\large \frac{330}{185}$ - the y-scale of everything inside must also scale by the same ratio.

For example, if the circle has original y-scale $34$, then the new y-scale will be $34 \times \frac{300}{185}$ which is about $60.6$.

The same ratio logic holds true for the x-scales of the objects, and also for coordinates - assuming the center of your resizing is $(0,0)$, an arbitrary point $(x,y)$ will get sent to $(\frac{83x}{185}, \frac{330y}{185})$ (using the ratios in your example).

  • 0
    thanks lopsy....i had something kinda close, but i'm trying to use your advice now...one more question: what if the center of the resizing were 556,785 for example (this would be the middle of the bounding box that's doing the resizing) -- what would the coordinates be with that center in mind?2012-02-14