!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! @ c-poly
!
! &1: rectangle or ellipse
! &2: xcenter [arcsec]
! &3: ycenter [arcsec]
! &4: major   [arcsec]
! &5: minor   [arcsec]
! &6: pa      [degree]
!
! Define and draw a polygon
!
! J.Pety 2005-2007
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Go to radian from input units
define double center[2] major minor pa
define logical show  
let center '&2*sec' '&3*sec'
let major '(&4/2.0)*sec'
let minor '(&5/2.0)*sec'
let pa    'pi*(90-&6)/180.0'
if (pro%narg.eq.7) then
   let show &7
else
   let show yes
endif
!
! Define number of gons
define integer ngons
if ("&1".eq."ellipse") then
   let ngons 100
else if ("&1".eq."rectangle") then
   let ngons 4
else
   message e poly "Unknown polygon type: &1"
   return base
endif
!
define real xygons[ngons,2] cospa sinpa rx ry cangle
let cospa cos(pa)
let sinpa sin(pa)
!
if ("&1".eq."ellipse") then
   let cangle (2*pi)/ngons
   for igon 1 to ngons
      let rx major*cos(igon*cangle)
      let ry minor*sin(igon*cangle)
      let xygons[igon,1] center[1]+rx*cospa-ry*sinpa
      let xygons[igon,2] center[2]+rx*sinpa+ry*cospa
   next
else
   let xygons[1,1:2] 'center[1]+major*cospa+minor*sinpa' 'center[2]+major*sinpa-minor*cospa'
   let xygons[2,1:2] 'center[1]+major*cospa-minor*sinpa' 'center[2]+major*sinpa+minor*cospa'
   let xygons[3,1:2] 'center[1]-major*cospa-minor*sinpa' 'center[2]-major*sinpa+minor*cospa'
   let xygons[4,1:2] 'center[1]-major*cospa+minor*sinpa' 'center[2]-major*sinpa-minor*cospa'
!   say '(center[1]+major*cospa+minor*sinpa)/sec' '(center[2]+major*sinpa-minor*cospa)/sec'
!   say '(center[1]+major*cospa-minor*sinpa)/sec' '(center[2]+major*sinpa+minor*cospa)/sec'
!   say '(center[1]-major*cospa-minor*sinpa)/sec' '(center[2]-major*sinpa+minor*cospa)/sec'
!   say '(center[1]-major*cospa+minor*sinpa)/sec' '(center[2]-major*sinpa-minor*cospa)/sec'
endif
!
!set marker 4 1 1 0
!draw marker 'center[1]' 'center[2]' /user radians
if (show) then
   poly xygons /plot /var
else
   poly xygons /var
end if
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
