Re: mouse within oval filled area: A solution using geometry

2011-11-14 Thread James Hurley
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



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: mouse within oval filled area: A solution using geometry

2011-11-13 Thread FlexibleLearning
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


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode