aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Zoom and centralize object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Zoom and centralize object" Watch "Zoom and centralize object" New topic
Author

Zoom and centralize object

Vinicius Moreira
Greenhorn

Joined: Jan 18, 2010
Posts: 27
Hello everybody, I am developing an application which will be necessary to implement the zoom on a particular map.
The Zoom I could implement using the AffineTransform class, but I would like the location where the user clicked the mouse to perform the zoom is centered on the screen.
How could I perform the calculation of the translation of the site click so it can be centered on the screen.
Thank you.

Vinícius
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2327
    
  28

To zoom into a particular point, you need to first move the point clicked on to the center and then zoom into the center. Moving a particular point to the center is called translation and zooming is achieved using a transformation called scaling. So, what you need to do is first translate, then scale. AffineTransform contains methods that apply both the transformations. SOmething like this



The distance that you want to translate is calculated from the center, so x and y above are the distance of the clicked point from the center.
Vinicius Moreira
Greenhorn

Joined: Jan 18, 2010
Posts: 27
Jayesh A Lalwani wrote:To zoom into a particular point, you need to first move the point clicked on to the center and then zoom into the center. Moving a particular point to the center is called translation and zooming is achieved using a transformation called scaling. So, what you need to do is first translate, then scale. AffineTransform contains methods that apply both the transformations. SOmething like this



The distance that you want to translate is calculated from the center, so x and y above are the distance of the clicked point from the center.


Thanks for responding.
For example, if I want to zoom into a point at coordinate x = 30 and y = 50 and my screen is 800 px wide and 600 high should I calculate the distance should I move this way: xCenter = 30 - 400 and yCenter = 50 - 300?
Vinicius Moreira
Greenhorn

Joined: Jan 18, 2010
Posts: 27
I implemented here but failed.
I'll post the code below.
Figure yet is not correctly centered. What could be wrong?

 
Consider Paul's rocket mass heater.
 
subject: Zoom and centralize object