home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / graphics / visualiz / 1162 < prev    next >
Encoding:
Internet Message Format  |  1992-07-28  |  3.4 KB

  1. Path: sparky!uunet!gatech!destroyer!caen!sdd.hp.com!cs.utexas.edu!rutgers!dziuxsolim.rutgers.edu!psi.rutgers.edu!ib.rl.ac.uk!CDO
  2. From: CDO@IB.RL.AC.UK (C D Osland)
  3. Newsgroups: comp.graphics.visualization
  4. Subject: Re: Arrowhead plotting routine, anybody?
  5. Message-ID: <9207281633.AA13042@psi.rutgers.edu>
  6. Date: 28 Jul 92 16:15:33 GMT
  7. References: <craven@CA.EMR.CG>
  8. Sender: nobody@psi.rutgers.edu
  9. Lines: 126
  10.  
  11. On 28 Jul 92 15:12:32 GMT <craven@CA.EMR.CG> said:
  12. >I ask this questions to avoid re-inventing the wheel.
  13. >
  14. >I am looking for a subroutine that given the head and tail
  15. >positions of a vector will calculate positions to
  16. >move to in order to draw an arrow head.   Has anybody
  17. >done this before?
  18. >
  19. >Jim
  20. The following section of Fortran MIGHT be useful - it is for
  21. a solid (i.e. filled area) arrow, with more hard-wired than
  22. should be.  I have adapted the code for this message, as there
  23. was a lot of extra code in the original section.
  24.  
  25. *
  26. *          'P' - generate a pointer
  27. *
  28.  
  29. *   On entry, NP = 1,2,3 or 4:
  30. *
  31. *                  1: two ends given, one arrow head
  32. *                  2: two ends given, two arrow heads
  33. *                  3: one end, length and angle given, one arrow head
  34. *                  4: one end, length and angle given, two arrow heads
  35. *
  36. *                     (These values are actually read in below.)
  37. *
  38. *             PWIDTH = pointer width
  39. *             PSIZE = pointer length
  40. *             RADFAC = conversion factor from degrees to radians
  41. *
  42.    95 CONTINUE
  43.       IF (NP.EQ.0) GOTO 96
  44.       IF ((NP.LT.1).OR.(NP.GT.4)) GOTO 96
  45.       IPTYPE = NP
  46.  
  47.    96 CONTINUE
  48.  
  49.       IF (IPTYPE.LT.3) THEN
  50.          READ (INFILE,*,END=180) X1,Y1,X2,Y2
  51.          ANGLE = ATAN2(Y2-Y1,X2-X1)
  52.       ELSE
  53.          READ (INFILE,*,END=180) X1,Y1,ALEN,ANGLE
  54.          ANGLE = ANGLE * RADFAC
  55.          X2 = X1 + ALEN * COS(ANGLE)
  56.          Y2 = Y1 + ALEN * SIN(ANGLE)
  57.       ENDIF
  58.  
  59.       X1 = X1 * FX + DX
  60.       Y1 = Y1 * FY + DY
  61.       X2 = X2 * FX + DX
  62.       Y2 = Y2 * FY + DY
  63.  
  64.       PP = PSIZE
  65.       RC = COS(ANGLE)
  66.       RS = SIN(ANGLE)
  67.  
  68.       XXX(1) = X2
  69.       YYY(1) = Y2
  70.  
  71.       XT = X2 - PP * RC
  72.       YT = Y2 - PP * RS
  73.       XXX(2) = XT + PSIZE * RS
  74.       YYY(2) = YT - PSIZE * RC
  75.  
  76.       XXX(3) = XT + PWIDTH * RS
  77.       YYY(3) = YT - PWIDTH * RC
  78.  
  79.       IF (MOD(IPTYPE,2).EQ.0) THEN
  80.  
  81. *        User has requested arrow heads at both ends
  82.  
  83.          NP = 11
  84.          XT = X1 + PP * RC
  85.          YT = Y1 + PP * RS
  86.          XXX(4) = XT + PWIDTH * RS
  87.          YYY(4) = YT - PWIDTH * RC
  88.  
  89.          XXX(5) = XT + PSIZE * RS
  90.          YYY(5) = YT - PSIZE * RC
  91.  
  92.          XXX(6) = X1
  93.          YYY(6) = Y1
  94.  
  95.          XXX(7) = XT - PSIZE * RS
  96.          YYY(7) = YT + PSIZE * RC
  97.  
  98.          XXX(8) = XT - PWIDTH * RS
  99.          YYY(8) = YT + PWIDTH * RC
  100.  
  101.       ELSE
  102.  
  103. *        User has requested arrow head only at X2,Y2 end
  104.  
  105.          NP = 8
  106.          XXX(4) = X1 + PWIDTH * RS
  107.          YYY(4) = Y1 - PWIDTH * RC
  108.  
  109.          XXX(5) = X1 - PWIDTH * RS
  110.          YYY(5) = Y1 + PWIDTH * RC
  111.  
  112.       ENDIF
  113.  
  114.       XT = X2 - PP * RC
  115.       YT = Y2 - PP * RS
  116.       XXX(NP-2) = XT - PWIDTH * RS
  117.       YYY(NP-2) = YT + PWIDTH * RC
  118.  
  119.       XXX(NP-1) = XT - PSIZE * RS
  120.       YYY(NP-1) = YT + PSIZE * RC
  121.  
  122.       XXX(NP) = XXX(1)
  123.       YYY(NP) = YYY(1)
  124.  
  125. *   GKS call to perform FILL AREA
  126.  
  127.       CALL GFA    (NP,XXX,YYY)
  128.       IRET = 0
  129.       RETURN
  130. *   Sorry about lack of comments!!!
  131.  
  132. Zero copyright protection - use at will - not the code I'm most proud of!
  133.  
  134. Cheers
  135.  
  136. Chris Osland
  137.