Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!mailrus!ncar!mephisto!prism!fsu!loligo!pepke From: pepke@loligo (Eric Pepke) Newsgroups: comp.sys.mac.hypercard Subject: Re: arrowheads at the end of lines. Message-ID: <393@fsu.scri.fsu.edu> Date: 7 Dec 89 20:44:10 GMT References: <1514@sequent.cs.qmc.ac.uk> Sender: news@fsu.scri.fsu.edu Reply-To: pepke@scri1.scri.fsu.edu (Eric Pepke) Organization: Supercomputer Computations Research Institute Lines: 66 Why is it that everybody wants to use angles and trigonometric functions to solve this problem and then acts surprised when it doesn't run very fast? Here is an easy solution based on elementary vector arithmetic that uses one square root, two divides (which could easily be converted into one divide and two multiplies), a few multiplies, and NO trigonometric functions. It's written in FORTRAN, and you have to convert it, but that's trivial. FRSTPT is roughly equivalent to MoveTo, VECTOR is roughly equivalent to LineTo, and SQRT is the FORTRAN square root function. SUBROUTINE ARROW(X1, Y1, X2, Y2, WIDTH, LENGTH) REAL X1, Y1, X2, Y2, WIDTH, LENGTH C C Eric Pepke, May 9, 1988 C C Draw an arrow from (X1, Y1) to (X2, Y2) C LENGTH is length of arrow head. WIDTH is width of arrow head. C Both LENGTH and WIDTH are absolute. This can easily be modified. C The arrow head is open. This, too, can be easily modified. C C X and Y components for normal vectors longitudinal and transverse C to the arrow, plus length of arrow REAL XL, YL, XT, YT, L C X and Y offsets for arrowhead based on longitudinal and C transverse contributions REAL DXL, DXT, DYL, DYT C C Draw shaft of arrow CALL FRSTPT(X1, Y1) CALL VECTOR(X2, Y2) C Calculate longitudinal and transverse vectors XL = X2 - X1 YL = Y2 - Y1 L = SQRT(XL * XL + YL * YL) IF (L .GT. 0.0) THEN C Draw arrow head C First make longitudinal and transverse vectors XL = X2 - X1 YL = Y2 - Y1 C Omit the next two lines to make relative size arrow head XL = XL / L YL = YL / L C XT = -YL YT = XL C Calculate the X and Y offsets DXL = LENGTH * XL DXT = WIDTH * XT DYL = LENGTH * YL DYT = WIDTH * YT C Draw one side of the arrow CALL VECTOR(X2 - DXL + DXT, Y2 - DYL + DYT) C Draw the other side C Change the next line to a VECTOR for a closed arrowhead CALL FRSTPT(X2 - DXL - DXT, Y2 - DYL - DYT) CALL VECTOR(X2, Y2) ENDIF END Eric Pepke INTERNET: pepke@gw.scri.fsu.edu Supercomputer Computations Research Institute MFENET: pepke@fsu Florida State University SPAN: scri::pepke Tallahassee, FL 32306-4052 BITNET: pepke@fsu Disclaimer: My employers seldom even LISTEN to my opinions. Meta-disclaimer: Any society that needs disclaimers has too many lawyers.