home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / CNC11TP.ZIP / HYPRDAM.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-01-19  |  3.5 KB  |  108 lines

  1. { Copyright (C) 1989 Adam Fritz, 133 Main St., Afton, N.Y. 13730 }
  2.  
  3. procedure StrokeHyperbola ( xc, yc : integer ; { center }
  4.                               a, b : word ; { radii }
  5.                                 ta : single ) ; { rotation angle (rad) }
  6.  
  7.      { HyprDAM - draw hyperbola using difference angle     }
  8.      {           method and `minimum' angle step           }
  9.  
  10. const
  11.    dx = 0.08836 ;
  12.    coshdx = 1.00390 ;
  13.    isinhdx : longint = $16A6 ;
  14.    icoshdx : longint = $10100 ;
  15.  
  16. var
  17.    ixar,iyar        : word ;    { aspect ratio parameters }
  18.    iar              : longint ; { aspect ratio B16 }
  19.    xx,yx            : single ;  { coordinate limits }
  20.    r,idx,ndx        : integer ; { loop control }
  21.    ixa0,ixa1,ixa2   : longint ; { generator B0 }
  22.    iyb0,iyb1,iyb2   : longint ; { generator B0 }
  23.    icosta,isinta    : longint ; { rotation B15 }
  24.    iacosta,iasinta  : longint ; { rotation - aspect B15 }
  25.    ix0,iy0,ix1,iy1  : integer ; { display variables B0 }
  26.    ix2,iy2,ix3,iy3  : integer ; { display variables B0 }
  27.  
  28. begin
  29.                                 { aspect ratio }
  30.    GetAspectRatio(ixar,iyar) ;
  31.    iar := SwapLong(longint(ixar)) div longint(iyar) ;
  32.                                 { step }
  33.    if a > b then
  34.       r := a
  35.    else
  36.       r := b ;
  37.  
  38.    if xc > 0 then
  39.       if xc > GetMaxX + 1 then
  40.          xx := xc
  41.       else
  42.          if xc > GetMaxX div 2 then
  43.             xx := xc
  44.          else
  45.             xx := GetMaxX - xc
  46.    else
  47.       xx := abs(xc) + GetMaxX + 1 ;
  48.  
  49.    if yc > 0 then
  50.       if yc > GetMaxY + 1 then
  51.          yx := yc
  52.       else
  53.          if yc > GetMaxY div 2 then
  54.             yx := yc
  55.          else
  56.             yx := GetMaxY - yc
  57.    else
  58.       yx := abs(yc) + GetMaxY + 1 ;
  59.  
  60.    ndx := Round(ln(2*sqrt(sqr(xx)+sqr(yx))/r)/ln(coshdx+dx)) ;
  61.                                 { offset and initialize }
  62.                                 { difference equations  }
  63.    ixa1 := SwapLong(longint(a)) ;
  64.    ixa2 := longint(a) * icoshdx ;
  65.    iyb1 := 0 ;
  66.    iyb2 := -longint(b) * isinhdx ;
  67.                                 { aspect and rotation }
  68.    icosta := Round(cos(ta) * 32768) ;
  69.    isinta := Round(sin(ta) * 32768) ;
  70.    iacosta := RoundScaleB16(iar * icosta) ;
  71.    iasinta := RoundScaleB16(iar * isinta) ;
  72.                                 { starting points }
  73.    ix0 := RoundScaleB16(LongHi(ixa1) * icosta shl 1) ;
  74.    iy0 := -RoundScaleB16(LongHi(ixa1) * iasinta shl 1) ;
  75.    ix2 := ix0 ;
  76.    iy2 := iy0 ;
  77.                                 { hyperbola }
  78.    for idx := 1 to ndx do begin
  79.                                 { step coordinates }
  80.       ixa0 := (ixa1 + ixa1 shr 8) shl 1 - ixa2 ;
  81.       iyb0 := (iyb1 + iyb1 shr 8) shl 1 - iyb2 ;
  82.  
  83.       ix1 := RoundScaleB16((LongHi(ixa0) * icosta +
  84.               LongHi(iyb0) * isinta) shl 1) ;
  85.       iy1 := RoundScaleB16((-LongHi(ixa0) * iasinta +
  86.               LongHi(iyb0) * iacosta) shl 1) ;
  87.  
  88.       Line(xc+ix0,yc+iy0,xc+ix1,yc+iy1) ;
  89.       Line(xc-ix0,yc-iy0,xc-ix1,yc-iy1) ;
  90.  
  91.       ix3 := RoundScaleB16((LongHi(ixa0) * icosta -
  92.               LongHi(iyb0) * isinta) shl 1);
  93.       iy3 := RoundScaleB16((-LongHi(ixa0) * iasinta -
  94.               LongHi(iyb0) * iacosta) shl 1);
  95.  
  96.       Line(xc+ix2,yc+iy2,xc+ix3,yc+iy3) ;
  97.       Line(xc-ix2,yc-iy2,xc-ix3,yc-iy3) ;
  98.                                 { ladder down }
  99.       ixa2 := ixa1 ;  ixa1 := ixa0 ;
  100.       iyb2 := iyb1 ;  iyb1 := iyb0 ;
  101.       ix0 := ix1 ;  iy0 := iy1 ;
  102.       ix2 := ix3 ;  iy2 := iy3
  103.  
  104.    end
  105. end ;
  106.  
  107. { Copyright (C) 1989 Adam Fritz, 133 Main St., Afton, N.Y. 13730 }
  108.