Rotating text (basic high school geometry) [SOLVED]
- Posted by petelomax Nov 03, 2023
- 831 views
Consider the following zoomed-in diagram:
-----N======== | +..W..9 TEXT : | : --:--1==:===== : :
Where TEXT is shown in its unrotated position, bounded by = and |.
The raw API rotate about the northwest corner, here denoted N, but I want to rotate about some other logical point, here we'll consider west, denoted W above.
[There are nine such similar logical points: NW, N, NE, W, C, E, SW, S, and SE.]
The . and : show the bounds of text rotated 90 about W, so to effect that I moved N to 9.
For 90 (only) I drew nine diddy-diagrams and figured out the shift needed to N, which were all +/- (width or height) [/2], some both.
Also shown above, bounded by - and |, is text rotated 180 about W, and to achieve that I would want to shift N to 1.
My question is: What is the easiest maths to shift N to effect such rotations, by any angle about any of the nine points?
Clearly to rotate 45 about W, I'd want to shift N to the mid-point between N and 9 on a circle with centre W.
In fact, of course, all rotations about W would first shift N to some point on that circle, and similar for the other eight.
Presumably it is all just a bit of sin() and cos(), maybe some matrix stuff?
Update: That quickly turned into a classic case of confessional debugging! I didn't twig until writing that down that
N would always be on a circle, which led me to search for "rotate point about another point", and bobs your uncle.