Take a look at the math here: Using the mouse position to zoom in on a map - #10 by scudly
and here’s one that supports rotation as well as pan and zoom: https://www.reddit.com/r/processing/comments/aecgdp/using_a_mousebased_ui_to_explore_truchet_tiles/