mouse within oval filled area: A solution using geometry

FlexibleLearning admin at FlexibleLearning.com
Sun Nov 13 16:04:43 EST 2011


For those who do not have LC5 or AE (ideas already suggested), here is a
solution to detect whether a point is within the filled area of an oval
graphic using polar geometry. It is offered as a starting point for a more
compact solution.

on mouseUp
  --| Syntax: isWithinSegment(long ID,point)
  put isWithinSegment(the long id of grc "myOval",the mouseLoc)
end mouseUp

function isWithinSegment pGrc.obj,pLoc
  --| pGrc.obj is the long id of the graphic
  --| pLoc is a point expressed as x,y
  --| Returned value is "TRUE" or "FALSE"

  if word 1 of pGrc.obj <> "graphic" then return ""
  if the style of pGrc.obj <> "oval" then return ""

  put the startAngle of pGrc.obj into tSA
  put the arcAngle of pGrc.obj into tAA
  put the width of pGrc.obj into W
  put the height of pGrc.obj into H
  put item 1 of the loc of pGrc.obj into objX
  put item 2 of the loc of pGrc.obj into objY
  put item 1 of pLoc into pointX
  put item 2 of pLoc into pointY

  --| 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

  return (tAngle>= tSA) AND (tAngle<=tSA+tAA)

end isWithinSegment


Hugh Senior
FLCo





More information about the use-livecode mailing list