Let's say we have a triangle within an image. We zoom into the image, where the center of the zoom is where our cursor is.
The triangle needs to translate and scale along with the zoom of the image.
For example, in the orginal unzoomed image I have the points:
original image triangle: (212,162) , (172,162) , (192,122
Then, after zooming in, we get the points:
2x zoom triangle: (231,173) , (151, 173) , (191,93)
Here is some information I know. The offset for the x and y from the original image to the new image are 97 and 76 respectively. And the image scaled by a factor of 2. Also, the actual image size, the x and y number of pixels, remains the same.
I am able to correctly calculate the new point's location based on the original frame's points using
x = (og_x-ZoomOffsetX)*ZoomLevel + ZoomLevel/2;
y = (og_y-ZoomOffsetY)*ZoomLevel + ZoomLevel/2;
where og_x, og_y are x and y in the original frame, offsetX and Y are the offsets based on where we are zoomed in on the frame (relative to the original image), and ZoomLevel is the factor by which we are zoomed (relative to the original image) which ascends 2,4,8...
Then, the next set of points are
4x zoom triangle: (218,222), (58,222), (138, 62)
where the zoom is now at 4x from the original and the x and y offset are 158 and 107 respectively, relative to the original.
Then,
8x zoom triangle: (236,340), (-84,340), (76, 20)
where the zoom is now at 8x the original and the x and y offset are 183 and 120 respectively.
What do I need to know/ what parameters do I need, to give the new (x,y) coordinates of the now scaled and translated (due to the zoom) triangle, based only on the immediately previous image? i.e. for the 8x zoom, based on the 4x zoom vs for the 8x zoom based on the original image. I can't figure it out with the information that I have.
Note: I am actually not positive whether the offset is relative to the original image or the prior image.. I am reading someone else's code and trying to understand it. ZoomLevel is definitely relative to the original image though.
Also, if it helps come up with a solution, this is all written in cpp, this zooming is being done in a qt widget, where the points are defined using QPointF from QT