Xref: utzoo comp.cog-eng:1481 comp.sys.mac:44181 comp.sys.mac.hypercard:2871 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!mitel!sce!cognos!neptune!writer From: writer@neptune.UUCP (Writer) Newsgroups: comp.cog-eng,comp.sys.mac,comp.sys.mac.hypercard Subject: Re: pie menus Message-ID: <712@neptune.UUCP> Date: 8 Dec 89 19:00:24 GMT References: <4352@ur-cc.UUCP> <2477@draken.nada.kth.se> Reply-To: writer@neptune.UUCP (Nigel Robinson) Organization: Cognos Inc., Ottawa, Canada Lines: 68 In article <2477@draken.nada.kth.se> krona@nada.kth.se (Kjell Krona) writes: >I have made a VERY simple stack with pie-menus... >... This is simple with four slices, but rapidly becomes more complicated... This got me thinking and programming, so here is my gift to the world: -a button that, when clicked, returns the angle from the central point of the button. This is based on the following assumptions (please don't abuse me if I did this un-mathematically... it's been years since a history prof has asked me to calculate the cosine of Napoleon.) Quadrants and angles: ---0/360--- ..4..|..1.. .....|..... 270 ----------- 90 deg ..3..|..2.. .....|..... --180 deg-- Here's the button script: on mouseUp put the rect of me into var put trunc((item 1 of var+item 3 of var)/2) into rx put trunc((item 2 of var+item 4 of var)/2) into ry -- rx and ry are the coordinates of the middle of the button if (item 1 of the clickloc)> rx then put "1 2" into var1 else put "3 4" into var1 -- if the click is on the right-hand side of the vertical -- centerline, then it is in quadrant 1 or 2 if (item 2 of the clickloc)> ry then put "2 3" into var2 else put "1 4" into var2 -- if the click is below the horizontal centerline, -- then it is in quadrant 2 or 3 repeat with count = 1 to 4 if var1 contains count and var2 contains count then put count into quad end repeat -- find the shared quadrant -- quad has the appropriate quadrant number in it (see diagram) put (item 1 of the clickloc)-rx into lx put -1*((item 2 of the clickloc)-ry) into ly -- align lx and ly (the click) to the center point of the button, -- in standard x-y coordinates (not the edge of the screen) if quad = 1 then put 0 into temp if quad = 2 then put -180 into temp if quad = 3 then put 180 into temp if quad = 4 then put -360 into temp -- housekeeping to keep the angle and the quadrants correct put abs(trunc(temp+(atan((abs(lx)/abs(ly)))*57.730721))) into ang put ang -- the angle! (Yay!) end mouseUp So there you have it... many apologies if I've typo'd. Your button can be any size, and if you are using it with a diagram, then put it on the background level, or make it transparent. Center it around a pie chart, and this should give you enough information to determine where in the pie the user clicked. You could use (lx^2+ly^2) = r^2 (where r is the radius of the pie) to check if the user is within the bounds of the circle. -Nigel, Waterloo co-op at large.