!   TITLE:  equilat_poly.mac (SM_TOOL)
!
!
!   OBJECTIVE:
!
!   This sub-macro creates an equilateral symmetric polygon.
!
!
!   COMMAND SYNTAX:
!
!       METHOD = 's':
!                           (1)     (2)       (3)       (4)     (5)      (6)
!            EQUILAT_POLY, mthd, side_leng, num_side, a_or_l, strt_ang, z_pos
!
!
!       METHOD = 'o':
!                           (1)   (2)     (3)       (4)     (5)      (6)
!            EQUILAT_POLY, mthd, r_out, num_side, a_or_l, strt_ang, z_pos
!
!
!       METHOD = 'i':
!                           (1)   (2)     (3)       (4)     (5)      (6)
!            EQUILAT_POLY, mthd, r_in, num_side, a_or_l, strt_ang, z_pos
!
!
!   ARGUMENTS:
!
!       (1) mthd = the method used to create the polygon
!
!               's' = known side length
!
!               'o' = known outer radius
!
!               'i' = known inner radius
!
!       (2) (mthd = 's') side_leng = the length of each side of the polygon.
!
!           (mthd = 'o') r_out = the outer radius of the corners.
!
!           (mthd = 'i') r_in = the inner radius, measured from the origin
!                               of the active C.S. to the sides of the polygon.
!
!       (3) num_side = number of sides to the polygon.
!
!       (4) a_or_l = argument to determine if an area is to be made of the
!                    polygon or remain as lines:
!
!                   0 (or blank)= create lines only
!
!                   1 = create an area form the polygon
!
!       (5) strt_ang = the start angle of the 1st corner of the polygon.
!
!       (6) z_pos = the Z position of the polygon along the Z axis.
!
!
!   DESCRIPTION:
!
!   The polygon is created such that the Z axis of the active coordinate
!   system is concentric to the polygon. The coordinate system need not be
!   a cylindrical C.S.
!
!   The polygon may be created by 1 of 3 methods:
!
!           1.)     A user defined side length ('s')
!           2.)     A user defined outer corner radius ('o')
!           3.)     A user defined inner side radius ('i')
!
!   The number of sides of the polygon, the start angle of the first outer
!   corner, and the Z position must be specified.
!
!   This macro returns the values of side length, inner radius and outer
!   radius calculated by the algorithm in the parameters SLENG_, RIN_ and
!   ROUT_, respectively.  These values may be used for future modeling tasks
!   if desired.
!
!   Run EQUILAT_POLY_DRAW.MAC for a diagram of arguments.
!
!
!
*get,prkey_,active,0,prkey
/nopr

!
mthd_=arg1
dim_=arg2
numsid_=arg3
aorl_=arg4
strtang_=arg5
zpos_=arg6
!
!
*get,ptyp_,parm,mthd_,type
!
*if,ptyp_,ne,3,then
    mthd_='o'
*endif
!
a_=360/numsid_
!
*if,mthd_,eq,'s',then
    sleng_=dim_
    rout_=(sleng_/2)/(sin((a_/2)*rconv))
    rin_=rout_*cos((a_/2)*rconv)
*elseif,mthd_,eq,'o',then
    rout_=dim_
    sleng_=2*rout_*sin((a_/2)*rconv)
    rin_=rout_*cos((a_/2)*rconv)
*elseif,mthd_,eq,'i',then
    rin_=dim_
    rout_=rin_/(cos((a_/2)*rconv))
    sleng_=2*rout_*sin((a_/2)*rconv)
*endif
!
*get,actcs_,active,,csys
*get,ccstyp_,cdsy,actcs_,attr,kcs
!
*if,ccstyp_,ne,1,then
    create_cs,0,,1,0,0,0,0,0,0
*endif
!
*if,strtang_,le,0,then
    ang_convert,'strtang_',0,'ulimit'
    ulimit=ulimit-a_
    !
    *if,ulimit,lt,0,then
        ang_convert,'ulimit'
    *endif
*else
    ulimit=(360+strtang_)-a_
*endif
!
*do,ij_,strtang_,ulimit,a_
    k,,rout_,ij_,zpos_
*enddo
!
*if,aorl_,eq,0,then
    create_lines
*else
    create_area
*endif
!
csys,actcs_
!
lplot
!
*set,ij_,
*set,dim_,
*set,numsid_,
*set,strtang_,
*set,zpos_,
*set,ptyp_,
*set,ulimit_,
*set,a_,
*set,actcs_,
*set,ccstyp_,
*set,aorl_,
*set,rin_,
*set,rout_,
*set,mthd_,
*set,sleng_,


*if,prkey_,eq,1,then
    /go
*endif