• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Zoom and centralize object

 
Vinicius Moreira
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I implemented here but failed.
I'll post the code below.
Figure yet is not correctly centered. What could be wrong?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic