home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / CNC11TP.ZIP / ELIPRA.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-01-19  |  1.9 KB  |  57 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.      { ElipRA - draw ellipse using rotation angle method }
  8.  
  9. var
  10.    ixar,iyar        : word ;    { aspect ratio parameters }
  11.    ar               : single ;  { aspect ratio }
  12.    da,cosda,sinda   : single ;  { step angle and functions }
  13.    t,xa,ya,xb,yb    : single ;  { coordinate variables }
  14.    r,ida,nda        : integer ; { loop control }
  15.  
  16. begin
  17.                                 { aspect ratio }
  18.    GetAspectRatio(ixar,iyar) ;
  19.    ar := ixar/iyar ;
  20.                                 { step angle and functions }
  21.    if a > b then
  22.       r := a
  23.    else
  24.       r := b ;
  25.    da := 2.0 * sqrt(1.0/r) ;
  26.    nda := Round(2.0 * Pi / da) ;
  27.    if Odd(nda) then Inc(nda) ;
  28.    da := 2.0 * Pi / nda ;
  29.    cosda := cos(da) ;
  30.    sinda := sin(da) ;
  31.                                 { coordinate variables with }
  32.                                 { rotation, offset, aspect, }
  33.                                 { prescale and reflection   }
  34.    xa := (a+dr) * cos(ta) ;
  35.    ya := -(b+dr) * sin(ta) ;
  36.    xb := (b+dr) * cos(ta) * ar ;
  37.    yb := -(a+dr) * sin(ta) * ar ;
  38.                                 { starting point }
  39.    MoveTo(xc+Round(xa),yc+Round(yb)) ;
  40.                                 { ellipse }
  41.    for ida := 1 to nda do begin
  42.                                 { rotate coordinates }
  43.       t := xa * cosda - ya * sinda ;
  44.       ya := xa * sinda + ya * cosda ;
  45.       xa := t ;
  46.  
  47.       t := xb * cosda - yb * sinda ;
  48.       yb := xb * sinda + yb * cosda ;
  49.       xb := t ;
  50.                                 { draw chord }
  51.       LineTo(xc+Round(xa),yc+Round(yb))
  52.  
  53.    end
  54. end ;
  55.  
  56. { Copyright (C) 1989 Adam Fritz, 133 Main St., Afton, N.Y. 13730 }
  57.