I'm learning to script Photoshop and I have encountered a math problem. Basically I want to rotate a shape around an arbitrary point (the baseline of some text), but Photoshop only allows me to rotate around corner or center points. I think I need to rotate the shape around one of the constrained points (the center point in my illustration) and then translate the result to align with the arbitrarily rotated shape. How could I calculate the translation mathematically?
2026-03-30 20:39:30.1774903170
On
Rotate shape around two points, calculate translation
876 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
3
There are 3 best solutions below
0
On
Let $p_1$ and $p_2$ be the two points. Let $r_{\theta}$ represent rotating the points around the origin for an angle of $\theta$.
The rotations are given by $$f_1(p) = r_{\theta}(p - p_1) + p_1$$ $$f_2(p) = r_{-\theta}(p - p_2) + p_2$$ $$f_2(f_1(p)) = r_{-\theta}(r_{\theta}(p - p_1) + p_1 - p_2) + p_2$$
Rotation is a linear operation ($r_{\theta}(sp + p') = sr_{\theta}(p) + r_{\theta}(p')$, so it distributes over the difference
$$f_2(f_1(p)) = r_{-\theta}(r_{\theta}(p - p_1) + p_1 - p_2) + p_2$$ $$ = (p - p_1) + r_{-\theta}(p_1 - p_2) + p_2$$ $$ = p + r_{-\theta}(p_1 - p_2) - (p_1 - p_2)$$


I got it working. It turned out to be simpler than I thought. Just had to rotate the preset anchor point around the arbitrary point and translate by the difference. In Adobe Photoshop Javascript, it looks like this: