Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!pt.cs.cmu.edu!andrew.cmu.edu!ba0k+ From: ba0k+@andrew.cmu.edu (Brian Patrick Arnold) Newsgroups: comp.sys.mac.hypercard Subject: Re: arrowheads at the end of lines. Message-ID: Date: 8 Dec 89 17:29:15 GMT References: <1514@sequent.cs.qmc.ac.uk>, <393@fsu.scri.fsu.edu> Organization: Mechanical Engineering, Carnegie Mellon, Pittsburgh, PA Lines: 63 In-Reply-To: <393@fsu.scri.fsu.edu> Hello there, no offense to Mr. Pepke, but if you re-read my last post: >We have tried to replace the trig [see my last post] with more >straightforward calculations to speed up this algorithm, but this >actually slowed things down a bit. Avoiding trig: ---------------------------------- ON DrawALink fromLoc,toLoc,toSize --| Draw an arrow between Locs, with arrow head adjusted to touch --| an edge of the rectangle of toSize at toLoc. --| Assumes SetDrawMode has been called to set line width --| and polysides=3. --| Modified by Max to speed up and avoid trig calcs. June 18/89 put (item 1 of toLoc - item 1 of fromLoc) into delx put (item 2 of toLoc - item 2 of fromLoc) into dely -- Scale endpoint (toLoc) to bring arrow to edge of button. -- w,h is the signed vector from the center of the button -- to the corner of the button nearest to fromLoc. put Round(((word 1 of toSize)/2)*delX/Abs(delX)) into w put Round(((word 2 of toSize)/2)*delY/Abs(delY)) into h IF abs(dely/delx) < abs(h/w) THEN -- Arrow to left or right of button rectangle subtract w from item 1 of toLoc subtract Round(Abs(w)*dely/Abs(delx)) from item 2 of toLoc ELSE -- Arrow to top or bottom of button rectangle subtract h from item 2 of toLoc subtract Round(Abs(h)*delx/Abs(dely)) from item 1 of toLoc END IF -- generate center point for arrow head (an equilateral triangle) put 5 into headR -- Radius of arrow head put toLoc into arrowLoc put Sqrt(delX*delX + delY*delY) into hypotenuse subtract Round(headR*delX/hypotenuse) from item 1 of arrowLoc subtract Round(headR*delY/hypotenuse) from item 2 of arrowLoc -- do the drawing choose regular polygon tool drag from arrowLoc to toLoc -- draw a triangle choose line tool drag from fromLoc to arrowLoc END DrawALink ---------------------------------- What's different about this code compared to the Fortran example is that we scale the endpoint to be flush with a rectangle at the destination. Also, using the polygon tool saves you from drawing a couple of extra lines. We found this version to be a bit slower than our trig version. I attribute this to interpreted HyperTalk execution overhead. If you remain unconvinced, you can do your own timing tests. I recommend the trig version for arrow drawing as presented in my last post, or writing an XCMD to do the math. - Brian