Math wizardry
Roger.E.Eller at sealedair.com
Roger.E.Eller at sealedair.com
Sun Oct 16 22:12:52 EDT 2005
For anyone interested, the modifications I made to Jim's original function
will now return a negative or positive angle that can be used to set the
angle property of an image object. This is great for rotating an image by
simply drawing a line object at the angle you desire.
function theGeometricalAngle p1,p2
--Geometrical angle of line defined by the two points p1 and p2
get the paramcount
if it is 1 then
put line 2 of p1 into p2
put line 1 of p1 into p1
end if
put item 1 of p2 - item 1 of p1 into dx
put item 2 of p2 - item 2 of p1 into dy
put atan2(dy,dx) into tAngle
--Add or subtract pi as needed.
switch
case tAngle < 0
put (tAngle + pi)*(360/pi) into tAngle
break
case tAngle > pi
put (tAngle - pi)*(360/pi) into tAngle
break
default
put tAngle*(360/pi) into tAngle
end switch
--Change to negative/positive angle format.
if (360-tAngle)/2 <= 90 then
return round((360-tAngle)/2)
else
return round(((360-tAngle)/2)-180)
end if
end theGeometricalAngle
--
Roger Eller <roger.e.eller at sealedair.com>
More information about the use-livecode
mailing list