• Post Reply Bookmark Topic Watch Topic
  • New Topic

Best/most common way to zoom in to a graph?  RSS feed

 
Dan Kao
Greenhorn
Posts: 18
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I've recently started on a small 2D grapher project (for fun) made in Java.
The problem I'm having is that I can't seem to find a good way to zoom reliably/comfortably.
My current zoom implementation uses something similar to this:



The problem is, with this type of zooming, it seems to "slow down" as you go out, and as you go inward it eventually flips the graph when it reaches negative zoom

How could I implement a "smoother" zoom?

Thanks!
example.png
[Thumbnail for example.png]
This is the graph of cos(x), when the zoom is negative - it
 
Stephan van Hulst
Saloon Keeper
Posts: 7817
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Possibly by incrementing your zoom exponentially. You should use the current zoom value in determining the increment.
 
Dan Kao
Greenhorn
Posts: 18
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried something like

and it works well.
Thanks for the suggestion!
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know where the calling code is getting the value passed as double s, but it appears to me that if all you're using is its signum, that should be a boolean parameter instead.
 
Piet Souris
Rancher
Posts: 1984
67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about using a Graphics2D in which you set the relevant coordinate system?
That way you let the computer do all the hard work, and it would simplify your
drawing function.

Greetz,
Piet
 
Campbell Ritchie
Marshal
Posts: 55781
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree with PS.

Not necessarily in this order:
Copy the Graphics object with its create method.
Cast that to Graphics2D.
Use the scale method on that G2D object; use the same scaling factor for both arguments.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!