You are here:

Calculus/Scaling a rectangle away from a fixed point

Advertisement


Question

Scale Example
Hello,

I have a problem which I believe falls into the realm of calculus, but I'm no expert (that's why I'm here!). At the most basic level, I have two rectangles; one is fixed at a certain size/placement (A), the other (B) can be changed on the fly via matrix transformations to vary its scale and translation. I need to provide a way that, no matter where B is or what scale it is, it can be fit to the extents A (without changing B's aspect ratio). This is easy enough to do when broken down like this: 1) Translate the center of B to the center of A, 2) Scale B outward from its center point until it hits either the horizontal or vertical bounds of A (whichever comes first).

My issue however is that I need to do this as a seamless operation, I need to scale B from a fixed point so that, when scaled, it will fit perfectly within A. Finding the scale is a simple ratio of A's height to B's height or A's width to B's width, whichever is smaller is the scale factor I use. The point at which to scale from however is very puzzling to me.

See the attached image... the black lines/text is what I've been calling A, which is my canvas or display. It's essentially the fourth quadrant of a cartesian plane, the top left being 0,0, but going down is actually positive Y in my case (not sure this matters). I know that if I need to get the shape from the Start to the End as shown, the point to scale from will always fall somewhere on a vector moving outward from the canvas center through B's center. In the scenario drawn, it will most likely be a point a little southwest of B's center (so the bottom left point moves at a slower rate than the rest). I need to be able to figure this out no matter what the scenario though, wherever B is located I need a general formula that will figure out the exact point to scale from.

Please let me know if this is in your realm of expertise or if more information is required.

Thanks in advance for your time!

Answer
For the big rectangle, I will put it in x-y coordinates and for the smaller rectangle,
I will put it in (w,z) coordinates, where w and x are colinear and z and y are colinear.

For the big rectangle, the base (bottom left) corner is at (x0, y0) and the opposite corner is at (x1,y1).  Thus, the width is x1-x0 and the height is y1-y0.  For the smaller rectangle, put the base at (w0,z0) and the top right corner at (w1,z1).  Here as well, the width is w1-w0 and
the height is z1-z0.

Since conversion is linear, w and z can be defined ast w = w0 + (x-x0)(w1-w0)/(x1-x0) and
z = z0 + (y-y0)(z1-z0)/(y1-y0).

As can be seen, the point (x0,y0) will map to (w0,z0) and the point (x1,y1) will map to (w1,z1).

Is this the transformation you're looking for in this problem?
If yes, you're welcome.

Scotto

Expertise

Any kind of calculus question you want. I also have answered some questions in Physics (mass, momentum, falling bodies), Chemistry (charge, reactions, symbols, molecules), and Biology.

Experience

Experience in the area: I have tutored students in all areas of mathematics for over 25 years. Education/Credentials: BSand MS in Mathematics from Oregon State University, where I completed sophomore course in Physics and Chemistry. I received both degrees with high honors. Awards and Honors: I have passed Actuarial tests 100, 110, and 135.

Publications
Maybe not a publication, but I have respond to well oveer 7,500 questions on the PC. Well over 2,000 of them have been in calculus.

Education/Credentials
I aquired well over 40 hours of upper division courses. This was well over the number that were required. I graduated with honors in both my BS and MS degree from Oregon State University. I was allowed to jump into a few junior level courses my sophomore year.

Awards and Honors
I have been nominated as the expert of the month several times. All of my scores right now are at least a 9.8 average (out of 10).

Past/Present Clients
My past clients have been students at OSU, students at the college in South Seattle, referals from a company, friends and aquantenances, people from my church, and people like you from all over the world.

©2012 About.com, a part of The New York Times Company. All rights reserved.