Fixing the Drift in Shape Rotations
steveruiz.me
steveruiz.me
There are minimum bounding circle algorithms that are O(n) where n is the number of points, but n can get big enough that you may not want to be doing that in an interactive program. You can put objects in a quadtree or similar to look them up quickly, and that may let you discard entire strokes in e.g. Welzl's bounding circle algorithm, but with stroke or curve data you'll still need to search along each one somehow for the extreme points by whatever measure you're using (and a Bezier curve has uncountably infinitely many points, so maybe you can only find an approximate bounding circle?).
This is the kind of thing where there are plenty of well-established algorithms (although there might not be a good off-the-shelf implementation in your language of choice). I doubt efficiency is going to be a problem unless you have many thousands of points.
Many thousands of points is exactly what you have in a page of handwriting. They're organised into strokes, which should help.
For example, the center of mass between earth and the sun is deep inside the sun, IIRC, so it would almost rotate around the sun.
So, if you have the sun showing at the left of your screen, earth at the right, and rotate that pair over 180 degrees, the sun would stay put, and earth would move off-screen.
You could auto-scroll to keep both on-screen, but I don’t think users would find either a good choice.
In general, I think users would expect a rectangle with some parts cut out if it to keep the same bounds after a 180 degree rotation, or a circle with some parts after any rotation.
Uhh, what? Why doesn't the rotated group have the same centre as the original? The article glosses right over this without explaining it. Is it floating point imprecision? Is it from rasterization?
If I'm being less un-charitable, the reason is that this bug is way down the list of priorities and fixing it with a proper solution is a lot of code and work that won't result in any new revenue.
Suppose that you have three boxes like this:
* - - - * . . . * - - - *
| | | |
| | | |
| | | |
* - - - * * - - - *
. .
. @ .
. .
. * - - - *
. | |
. | |
. | |
. . . . . . . . * - - - *
The pivot for rotating them will be at the @ in the center of the bounding box around the three. If you then turn that counterclockwise by 45 degrees: . . . . . . . . . * . . . . . . . . .
. / \ .
. / \ .
. * * .
. \ / .
. \ / .
. * @ * .
. / \ / \ .
. / \ / \ .
* * * *
. \ / \ / .
. \ / \ / .
. . . * . . . . . . . . . . . * . . .
then the center of the bounding box has now moved towards the corner of what was originally the upper right square (because there isn't a fourth square to complete the symmetry and push the bottom of the box around the three squares down). Rotating again will now pivot around this new point rather than the original and a rotation 45 degrees clockwise back to the original angle will now have shifted the boxes.Honestly, I'd think the correct solution here would be to pivot around the center-of-mass or some other rotationally-invariant point.
But yeah, using a rotationally-invariant point would be better than the stateful fix the article goes for.
Center-of-mass would make sense except it might do strange things if you have a mix of solid shapes and lines. How much mass should the lines have?
Using the centre of the bounding circle is probably best, as others in this discussion have suggested.
Maybe the appropriate choice here is grouping, like we see app use folders for these. That way you get what you're talking about and it's obvious to the user / it's based on their choice.
as an artist who uses these kinds of tools, and someone who'se had to design easy to use interfaces, it's hard to convay "invariant center of mass" when the selection for multiple shapes usually involves drawing a screen aligned rectangle (which has a convenient and intuitive center point)