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

  1. { Copyright (C) 1989 Adam Fritz, 133 Main St., Afton, N.Y. 13730 }
  2.  
  3. procedure StrokeEllipse ( xc, yc : integer ; { center }
  4.                             a, b : word ; { radii }
  5.                               ta : single ) ; { rotation angle (rad) }
  6.  
  7.      { ElipRAF - draw ellipse using rotation angle method  }
  8.      {           and fixed point arithmetic                }
  9.  
  10. var
  11.    ixar,iyar        : word ;    { aspect ratio parameters }
  12.    iar              : longint ; { aspect ratio B16 }
  13.    da               : single ;  { step angle }
  14.    icosda,isinda    : longint ; { step angle functions B16 }
  15.    ira,irb          : longint ; { offset radii B6 }
  16.    icosta,isinta    : longint ; { rotation variables B16 }
  17.    it,ixa,iya       : longint ; { coordinate variables B6 }
  18.    ixb,iyb          : longint ; { coordinate variables B6 }
  19.    r,ida,nda        : integer ; { loop control }
  20.  
  21. begin
  22.                                 { constraint test }
  23.    if (a < 511) and (b < 511) then begin
  24.                                 { aspect ratio }
  25.       GetAspectRatio(ixar,iyar) ;
  26.       iar := SwapLong(longint(ixar)) div longint(iyar) ;
  27.                                 { step angle and functions }
  28.       if a > b then
  29.          r := a
  30.       else
  31.          r := b ;
  32.       da := 2.0 * sqrt(1.0/r) ;
  33.       nda := Round(2.0 * Pi / da) ;
  34.       if Odd(nda) then Inc(nda) ;
  35.       da := 2.0 * Pi / nda ;
  36.       icosda := Round(cos(da) * 65536) ;
  37.       isinda := Round(sin(da) * 65536) ;
  38.                                 { offset and scale radii }
  39.       ira := a shl 6 + idr ;
  40.       irb := b shl 6 + idr ;
  41.                                 { scale rotation functions }
  42.       icosta := Round(cos(ta) * 65536) ;
  43.       isinta := Round(sin(ta) * 65536) ;
  44.                                 { coordinate variables with        }
  45.                                 { rotation, aspect, and reflection }
  46.       ixa := RoundScaleB16(ira * icosta) ;
  47.       iya := -RoundScaleB16(irb * isinta) ;
  48.       ixb := RoundScaleB16(RoundScaleB16(irb * icosta) * iar) ;
  49.       iyb := -RoundScaleB16(RoundScaleB16(ira * isinta) * iar) ;
  50.                                 { starting point }
  51.       MoveTo(xc+RoundScaleB6(ixa),yc+RoundScaleB6(iyb)) ;
  52.                                 { ellipse }
  53.       for ida := 1 to nda do begin
  54.                                 { rotate coordinates }
  55.          it := RoundScaleB16(ixa * icosda - iya * isinda) ;
  56.          iya := RoundScaleB16(ixa * isinda + iya * icosda) ;
  57.          ixa := it ;
  58.  
  59.          it := RoundScaleB16(ixb * icosda - iyb * isinda) ;
  60.          iyb := RoundScaleB16(ixb * isinda + iyb * icosda) ;
  61.          ixb := it ;
  62.                                 { draw chord }
  63.          LineTo(xc+RoundScaleB6(ixa),yc+RoundScaleB6(iyb))
  64.  
  65.       end
  66.    end
  67. end ;
  68.  
  69. { Copyright (C) 1989 Adam Fritz, 133 Main St., Afton, N.Y. 13730 }
  70.