Ok, this might be a little long-winded, but it hopefully shows the process better.
I took your original code (from your last post) and used it to create the mouse location function.
Your function does basically this - (for x values) where qx is the plot point, vx is the incoming NE coord, cx is the orig, sx is the scale factor and ox is the offset.
That gives us these equations:
qx = ((vx - cx) * sx) + ox
qy = ((cy - vy) * sy) - oy
Reworking these equations to use qx as the mouse loc and getting vx out (for the NE coord):
qx - ox = (vx - cx) * sx
. (qx - ox) / sx = vx - cx
. ( (qx-ox) / sx ) + cx = vx
and (. at the start of the line means "is the same as"):
qy + oy = (cy - vy) * sy
. (qy + oy) / sy = cy - vy
. (qy + oy) / sy = -vy + cy
. -(((qy + oy) / sy) - cy) = vy
Gives us:
Code: Select all
vx = ( (mouseX - tXOffset) / GXFactor) + tXOrig
vy = (( (mouseY + tYOffset) / GYFactor) - tYOrig) * -1
or
put ( (mouseX - tXOffset) / GXFactor) + tXOrig into vx
put (( (mouseY + tYOffset) / GYFactor) - tYOrig) * -1 into vy
In most cases you will find that just playing with the equations will give you the results - then it's just a case of wrapping them into code.
Hope that helps again,
Dave