File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other JSE/JEE APIs and the fly likes 2D translation question. 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 "2D translation question." Watch "2D translation question." New topic

2D translation question.

Darrin Smith
Ranch Hand

Joined: Aug 04, 2003
Posts: 276
The best way to relate my question is by scenario:

You have an application that draws an image on a screen. Let's say that image is just a big box. You select the point directly on the top left corner of the box. Let's say that point ON THE SCREEN is 100, 100 to make it easy. The user then moves that image to the right and zooms it. No rotation was involved. He then selects the same spot on the box...very top left. Of course since the box moved the screen coordinates are no longer 100, 100. Let's say they are now 120, 90.

How can you translate the 120, 90 back to what it would have been (100, 100) if the user had not panned and zoomed the image?

The code to move the image after the user pans and zooms looks like this. Note that the mState object also holds the X/Y coordinate the user touched on.

What is the formula that needs to be applied to that point to get it back to what it would have been pre-translation and scale in this code?

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: 2D translation question.
It's not a secret anymore!