Date: 05/11/2005 at 17:58:43 From: Cassi Subject: Zooming rectangle What is the math behind zooming rectangles? You see them all the time in computer programs, and even on calculators. For example, say you have a graph. You can create a zooming rectangle which will "zoom in" on whatever is in the rectangle. But all it's essentially doing is increasing the relative size and changing the position of the objects inside the rectangle. I'm trying to write a program that mimics a zooming rectangle (i.e., it zooms in on a line using math instead of some built-in function), but it's not working the way I think it should. I'm having problems because objects close to the center don't enlarge/move much, while objects close to the edge do.
Date: 05/12/2005 at 11:20:07 From: Doctor Ian Subject: Re: Zooming rectangle Hi Cassi, Whenever you're drawing anything on a computer screen, there are two coordinate systems involved. One is the set of coordinate axes where you're representing the thing to be drawn--a line, or a curve, or an ellipse, or whatever. The other is the set of coordinate axes on the display device. To draw something, you have to construct a mapping function that takes any point in the first coordinate system, and maps it into the second coordinate system. Note that for _most_ points in the first system, the corresponding point in the second system will be outside the drawing area, i.e., it won't show up. To construct the function, you need to know which point (a,b) in the first system corresponds to the lower-left corner (0,0) in the second system; and which point (c,d) in the first system corresponds to the upper-right corner (x_max,y_max) of the second system. Now, let's say you have a point (x,y) that is somewhere in the rectangle defined by (a,b) and (c,d). The scale factor is whatever takes (c-a,d-b) to (x_max,y_max), i.e., x_max y_max k_x = ----- k_y = ----- c - a d - b Now you can take any point (x,y) in the first system, and the place where it should show up is (x,y) -> ( (x-a) * k_x, (y-b)*k_y ) Convince yourself that if (x,y) is at (a,b), it will map to (0,0); and if (x,y) is at (c,d) it will map to (x_max,y_max). Does this help? - Doctor Ian, The Math Forum http://mathforum.org/dr.math/
Date: 05/12/2005 at 15:14:22 From: Cassi Subject: Thank you (Zooming rectangle) Thank you SO MUCH!!! Your answer was very clear and I finally understood what was going on. I was able to shorten my code from 52 lines down to 6. I had been working on this problem for far too long. I got a response extremely fast.
Search the Dr. Math Library:
Ask Dr. MathTM
© 1994- The Math Forum at NCTM. All rights reserved.