Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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?

share|improve this question
    
Where is the origin ($(0,0)$) of your coordinate system? –  Isaac Feb 14 '12 at 1:11
    
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. –  TimDog Feb 14 '12 at 2:22
add comment

2 Answers

up vote 3 down vote accepted

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)).$$

share|improve this answer
    
so awesome, this is working wonderfully...thanks very much. lopsy confirmed the height/width resizing, and this really helped me nail the x,y coordinates -- which was my biggest sticking point, so i'll award the answer here. –  TimDog Feb 14 '12 at 3:24
    
@Isaac I am assuming that $(c_x,c_y)$ and $(x_c,y_c)$ are the same in the above formula. Or am I missing something? –  asloob May 15 '13 at 6:42
    
@asloob: yup, fixed now, thanks. –  Isaac May 16 '13 at 1:43
add comment

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).

share|improve this answer
    
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? –  TimDog Feb 14 '12 at 2:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.