mouse within oval filled area
James Hurley
jhurley0305 at sbcglobal.net
Sun Nov 13 01:01:57 EST 2011
Hugh,
Would this help? The script below will draw a polygon that looks like an ellipse with a start and stop angle.
The trouble with the start angle and the arcangle in RR is that they are not polar angles but are related in a complex way:
arcAngle = arctangent( b/a * tangent(polarangle)
(Don't ask.)
And then use a mousewithin handler for the "oval" grc--actually a polygon
local a,b
on mouseUp
put 10 into tStartAngle -- Or whatever
put 250 into tEndAngle -- Or whatever
put 200 into a --Semi major axis
put 100 into b -- Semi minor axis
put 300 into x0 -- The origin
put 250 into y0 -- The origin
put x0,y0 & cr into tPoints
--Construct the points for the ellipse
repeat with i = tStartANgle to tEndANgle
put r(i) into tR
put round ( x0 + r(i) * cos(i*pi/180)), round(y0+r(i) * sin(i*pi/180)) into temp
put temp & cr after tPoints
end repeat
put x0,y0 after tPoints
--Construct the graphic
if there is no grc "oval" then create grc "oval"
set the style of grc "oval" to "polygon"
set the opaque of grc "oval" to true
set the points of grc "oval" to tPoints
end mouseUp
function r tA --Radial distance to the ellipse as afunction of the angle
put (cos(tA*pi/180))^2 / (a*a) + (sin(tA*pi/180))^2 / (b*b) into temp
return 1/sqrt(temp)
end r
> Has anyone worked out how to test if the mouseLoc is within the filled area
> of an oval graphic (defined by startAngle and arcAngle)? I was thinking
> polar coordinates, but this assumes a circle and a fixed radius which is not
> necessarily the case. A btter math brain than mine is needed!
>
> Hugh Senior
> FLCo
More information about the Use-livecode
mailing list