Rotate around Center of Mass

Ken Corey ken at kencorey.com
Mon Jan 9 09:15:09 EST 2012


I don't know why, but this question really stuck in my head.

So much so, when I stumbled across the 'crop' command I just had to write.

This isn't a full answer, unfortunately, but it's a start, methinks.

First off, let's assume your image is at the rect 100,100,200,200.
The center of the image is therefore 150,150.
Let's assume the "center of mass" is at 120,120.
If you set the angle of the image, you're rotating around the center of 
the image, not the center of mass.

So if you add a border around the image you can adjust the center and 
center of mass to be the same...and good news: the 'crop' command can 
make an image bigger as well as smaller!

If we add enough to shift the center of the image to be 125,125 and then 
adjust the angle, we're rotating around the center of mass.

crop image "testing" to 40,40,200,200.

Now, the center of the image is the same as the center of mass.  The 
rotation is then easy:
set the angle of image "testing" to angleInDegrees

Of course, now you have a larger image.  If you can use that, then so 
much the better.

If not, you have to decide what to do about parts of your image that are 
outside of your bounds.  Do you crop to the original rect of the image?  
Then you might lose bits.

Do you want to crop only to the new size of the image?  I don't know an 
easy way to do that...you *could* access the bits directly like this: 
(http://bit.ly/yI1wBj), and iterate across your image to find out your 
new extents, but that's extreme brute-force...

Hope this helps.

-Ken




More information about the use-livecode mailing list