Rotate around Center of Mass
jhurley0305 at sbcglobal.net
Sun Jan 8 14:44:26 CST 2012
The script below will allow you to rotate an image about any predefined point.
Create a button.
Create an image.
Place the button at any point relative to the image. (Perhaps use a grab me in a mousedown handler.)
Click the button.
The image will rotate about the center of the button.
(For your application you would replace the center of rotation with the center of mass.)
set the angle of img 1 to 0
put the loc of me into myLoc
--Set the coor of the rotation Pt
put item 1 of myLoc into x0
put item 2 of myLoc into y0
--Get the loc of the image
put the loc of img 1 into tLoc
put item 1 of tLoc into xC
put item 2 of tLoc into yC
--Get the distance between the roation pt and the image center
put sqrt ( (xC - x0 )^2 + (yC - y0)^2 ) into L
--Get the angle of the line from the rotation center to the image center
put atan2(yC-y0, xC-x0) *180/pi into phi0
put 0 into tAngle
repeat 360 times
set the angle of img 1 to -tAngle
put phi0 + tAngle into phi
set the loc of img 1 to (x0 + L * cos(phi*pi/180)), (y0 + L * sin(phi*pi/180))
add 1 to tAngle
wait 10 millisec --or whatever
grab me --So that you can relocate the rotation center.
> Message: 1
> Date: Sat, 7 Jan 2012 10:15:36 -0800 (PST)
> From: AcidJazz <mpezzo at gmail.com>
> To: use-revolution at lists.runrev.com
> Subject: Rotate around Center of Mass
> Message-ID: <1325960136367-4273701.post at n4.nabble.com>
> Content-Type: text/plain; charset=us-ascii
> Is there a way to rotate an image around it's center of mass? I teach
> statistics, and one of the definitions of the mean is that it is the balance
> point of a distribution. I'd like to actually show a distribution
> "balancing" back and forth, or actually spinning around its mean. But, if
> I take an image of a very skewed distribution of scores (long tail) and
> tried to rotate it, it would rotate around the center of the /image/, which
> would not necessarily be the mean of the distribution. I image that the
> solution involves extending the size of the image so that it is now centered
> on the mean, but without altering or moving the actual distribution. In
> BlueMango's Clarify, after you take a snapshot, you can extend the size of
> the image without stretching the picture. I would need a way to do that
> programmatically so that the horizontal center is the mean of the
> distribution. Any suggestions??
More information about the use-livecode