mouse within oval filled area: A solution using geometry

James Hurley jhurley0305 at sbcglobal.net
Mon Nov 14 08:49:09 EST 2011


Hugh,

You'll love the atan2 function. It takes care of all nasty bits at 90 and 270 degrees as well as dealing with the quadrants issues.

Use atan2(y,x) for angles measure clockwise from the x-axis

Use atan2(-y,x) for angles measure counterclockwise from the x-axis.

Jim Hurley


 --| Get the point's relative coordinates...
  put pointX - objX into x
  put pointY - objY into y

  if y=0 then
    --| Handle the exceptions...
    if x>0 then put 0 into tAngle
    else put 180 into tAngle
  else
    put atan ((x*H)/(y*W)) into tAngle
    --| Convert from radians to degrees...
    put (tAngle * 180 / pi) into tAngle
    --| Adjust the angle according to the quadrant...
    put (tAngle MOD 180)+90 into tAngle
    if y>0 then add 180 to tAngle
  end if






More information about the use-livecode mailing list