!   TITLE:  conic_section.mac (SM_TOOL)
!
!
!   OBJECTIVE:
!
!   This sub-macro creates a planar rectangle.
!
!
!   COMMAND SYNTAX:
!
!                      (1)    (2)      (3)     (4)  (5)    (6)      (7)
!       CONIC_SECTION, acs, R_minor, R_major, leng, ang, r_minor, r_major,
!
!                      rev_ang, N_seg
!                        (8)     (9)
!
!
!   ARGUMENTS:
!
!       (1) R_minor = the radius of the smaller diameter end of the conic
!                     section.
!
!       (2) R_minor = the radius of the smaller diameter end of the conic
!                     section.
!
!       (3) R_major = the radius of the larger diameter end of the conic
!                     section.
!
!       (4) leng = the length (or height) of the cone.
!
!       (5) ang = the angle of the outer cylindrical surface with respect
!                 to the axis of the cone.
!
!       (6) r_minor = the fillet radius of the smaller diameter end adjoining
!                     the smaller diameter surface and the outer cylindrical
!                     surface.
!
!       (7) r_major = the external fillet radius of the larger diameter end
!                     adjoining the outer cylindrical surface (base) with the
!                     adjoining plane of the larger diameter surface.
!
!       (8) rev_ang = total revolve angle of the conic section.
!                     [ If left blank, default is 360 degrees ]
!
!               NOTE: If a planar cross-section is desired (no revolve), then
!                     assign this argument -1.
!
!       (9) N_seg = number of volume segments in the total revolve angle.
!                   [ If left blank, default is 4 segments ]
!
!
!   DESCRIPTION:
!
!   The conic section is a complete or partial section of volumes constructed 
!   such that the base of the cone (the larger diameter end) is coincident with
!   the XY plane of the CS specified in argument 1, with the axis of the cone
!   along the +Z axis. The CS in argument 1 may be any type (i.e., crtesian,
!   cylindrical, etc.).
!
!   The length of the conic section is the the length along the Z axis, from the
!   base surface to the end surface, or point, of the cone.
!   
!   The conic section may have flat surfaced ends (partial cone), where the radii
!   of the ends may be specified in arguments 2 and 3.
!
!   The cone may have fillets at either or both end surfaces. The base fillets
!   radii, 'r_major' (argument 7), are fillets such that they are exterior to the
!   conic surface, thereby 'blending' the base of the cone to the XY plane.
!
!   The fillets at the smaller diameter end, 'r_minor' (argument 6), are fillets
!   that blend the conic surfaces to smaller diameter surfaces.
!
!   The conic section may be specified in the follwoing various combinations:
!
!           1.)  Specify both radii, and the cone length.
!
!           2.)  Specify one (either) radius, cone length and an angle.
!
!           3.)  Specify the base (major) radius, and an angle.
!                (This creates a full cone).
!
!           4.)  Specify the base (major) radius, and cone length.
!                (This creates a full cone).
!
!   To view a conic section created from this macro, run the following example
!   lines of code (must execute 'mod_assemb_prep' prior to running):
!
!                           CONIC_SECTION,0,1,5,7,45,,,,
!
!                           CONIC_SECTION,0,,5,7,,,2,,
!
!                           CONIC_SECTION,0,,5,6,30,0.5,1,240,5
!
!                           CONIC_SECTION,0,,5,,30,,2,,
!
!
!
*get,prkey_,active,0,prkey
/nopr
!
acs_=arg1
rmin_=arg2
rmaj_=arg3
leng_=arg4
ang_=arg5
rfmin_=arg6
rfmaj_=arg7
revang__=arg8
nvseg_=arg9
!
configuration,0
!
*if,revang__,eq,0,then
    revang__=360
*endif
!
*if,nvseg_,eq,0,then
    nvseg_=4
*endif
!
*if,rmin_,gt,0,then
    *if,rmaj_,gt,0,then
        *if,leng_,gt,0,then
            ang_=0
        *elseif,leng_,eq,0,then
            leng_=(rmaj_-rmin_)/tan(ang_*rconv)
        *endif
    *endif
*elseif,rmin_,eq,0,then
    *if,rmaj_,gt,0,then
        *if,ang_,gt,0,then
            *if,leng_,eq,0,then
                leng_=rmaj_/tan(ang_*rconv)
            *endif
        *endif
    *endif
*endif
!
*if,ang_,gt,0,then
    *if,rmin_,eq,0,then
        rmin_=rmaj_-leng_*tan(ang_*rconv)
    *elseif,rmin_,gt,0,then
        *if,rmaj_,ge,0,then
            rmaj_=rmin_+leng_*tan(ang_*rconv)
        *endif
    *endif
*endif
!
csys,acs_
create_cs,0,,0,0,0,0,0,0,0
!
*if,rmin_,gt,0,then
    k,,0,0,0
    k,,rmaj_,0,0
    k,,rmin_,0,leng_
    k,,0,0,leng_
*elseif,rmin_,eq,0,then
    k,,0,0,0
    k,,rmaj_,0,0
    k,,0,0,leng_
*endif
!
create_lines
!
*if,rmin_,gt,0,then
    *if,rfmin_,gt,0,then
        ln_fillet,km-1,rfmin_
        !
        *if,rfmaj_,gt,0,then
            k,,rmaj_+(1.5*rfmaj_),0,0
            init_entity_num
            lstr,km-5,km
            init_entity_num
            ldele,lm-5
            init_entity_num
            ln_fillet,km-5,rfmaj_
            ldele,lm-1,,,1
            init_entity_num
            lstr,km,km-8
            init_entity_num
        *endif
    *elseif,rfmin_,eq,0,then
        *if,rfmaj_,gt,0,then
            k,,rmaj_+(1.5*rfmaj_),0,0
            init_entity_num
            lstr,km-3,km
            init_entity_num
            ldele,lm-4
            init_entity_num
            ln_fillet,km-3,rfmaj_
            ldele,lm-1,,,1
            init_entity_num
            lstr,km,km-6
            init_entity_num
        *endif
    *endif
*elseif,rmin_,eq,0,then
    *if,rfmaj_,gt,0,then
        k,,rmaj_+(1.5*rfmaj_),0,0
        init_entity_num
        lstr,km-2,km
        init_entity_num
        ldele,lm-3
        init_entity_num
        ln_fillet,km-2,rfmaj_
        ldele,lm-1,,,1
        init_entity_num
        lstr,km,km-5
        init_entity_num
    *endif
*endif
!
isolate_lines
configuration,-1
!
al,all
init_entity_num
!
*if,revang__,ne,-1,then
    isolate_areas
    configuration,-1
    !
    revolve_aset,acs_,revang__,nvseg_
*endif
!
configuration,1
init_entity_num
!
aplot
!
*set,acs_,
*set,rmin_,
*set,rmaj_,
*set,leng_
*set,ang_,
*set,rfmin_,
*set,rfmaj_,
*set,revang__,
*set,nvseg_,
!
*if,prkey_,eq,1,then
    /go
*endif