!   TITLE:  ns_ln_fillet.mac (SM_TOOL)^M
!^M
!^M
!   OBJECTIVE:^M
!^M
!   This sub-macro creates a non-standard line fillet(s) at the specified^M
!   junction keypoint(s).^M
!^M
!^M
!   COMMAND SYNTAX:^M
!^M
!                       (1)     (2)    (3)^M
!       NS_LN_FILLET, rad_fil, ln_#1, ln_#2^M
!^M
!^M
!   ARGUMENTS:^M
!^M
!       (1) rad_fil = fillet radius^M
!^M
!       (2) ln_#1 = the 1st line^M
!^M
!       (3) ln_#2 = the 2nd line^M
!^M
!^M
!   DESCRIPTION:^M
!^M
!   This macro creates a non-standard fillet between 2 lines sharing the^M
!   keypoint specified in argument 1, 'jkp', with the fillet radius specified^M
!   in argument 2.^M
!^M
!   This macro is a utility function called by the command macro LN_FILLET for^M
!   the purpose of creating non-standard fillets, and is not intended for direct^M
!   use.^M
!^M
!^M
!^M
*get,prkey_,active,0,prkey^M
/nopr^M
!^M
irad__=arg1^M
ln1__=arg2^M
ln2__=arg3^M
!^M
ns_fillet_test,irad__,ln1__,ln2__,1^M
!^M
!   Ouput of NS_FILLET_TEST:^M
!       a.) ln_long = longer line number between LN_#1 and LN_#2
!       b.) lng_long = longer line length between LN_#1 and LN_#2
!       c.) kp_long = KP number at the non-junction end of the longer line
!       d.) kplong_1 = KP number at the 1st end of the longer line
!       e.) kplong_2 = KP number at the 2nd end of the longer line
!       f.) dir_lng = longer line direction relative to the junction KP
!   
!       g.) ln_shrt = shorter line number between LN_#1 and LN_#2
!       h.) lng_shrt = shorter line length between LN_#1 and LN_#2
!       i.) kp_shrt = KP number at the non-junction end of the shorter line
!       j.) kpshrt_1 = KP number at the 1st end of the shorter line
!       k.) kpshrt_2 = KP number at the 2nd end of the shorter line
!       l.) dir_sht = shorter line direction relative to the junction KP
!   
!       m.) ang_lns = angle between lines
!       n.) jkp = KP number at the junction of the 2 lines
!^M
phi_=ang_lns^M
long_=lng_long^M
shrt_=lng_shrt^M
!^M
*if,long_,eq,shrt_,then^M
    *if,phi_,eq,90,then^M
        cond_=11^M
    *elseif,phi_,gt,90,then^M
        cond_=12^M
    *elseif,phi_,lt,90,then^M
        cond_=13^M
    *endif^M
*elseif,long_,gt,shrt_,then^M
    *if,phi_,eq,90,then^M
        cond_=21^M
    *elseif,phi_,gt,90,then^M
        cond_=22^M
    *elseif,phi_,lt,90,then^M
        cond_=23^M
    *endif^M
*endif^M
!^M
d_=sqrt((long_**2)+(shrt_**2)-(2*long_*shrt_*cos(phi_*rconv)))^M
!^M
phi1_=(asin((long_*sin(phi_*rconv))/d_))*dconv^M
phi2_=(asin((shrt_*sin(phi_*rconv))/d_))*dconv^M
!^M
thetachk=90-phi2_^M
dchk_=sqrt((irad__**2)+(d_**2)-(2*irad__*d_*cos(thetachk*rconv)))^M
!^M
*if,cond_,eq,11,then^M
    !^M
    delta_=2*(asin((long_*sin((phi_/2)*rconv))/irad__))*dconv^M
    theta_=180-(phi_/2)-(delta_/2)^M
    !^M
    rpos_=sqrt((long_**2)+(irad__**2)-(2*long_*irad__*cos(theta_*rconv)))^M
    !^M
    create_cs,1,,1,jkp,kp_long,kp_shrt^M
    create_cs,0,,1,rpos_,phi_/2,0^M
    !^M
    l,kp_shrt,kp_long^M
    !^M
*elseif,cond_,eq,12,then^M
    !^M
    delta_=2*(asin((long_*sin((phi_/2)*rconv))/irad__))*dconv^M
    theta_=180-(phi_/2)-(delta_/2)^M
    !^M
    rpos_=sqrt((long_**2)+(irad__**2)-(2*long_*irad__*cos(theta_*rconv)))^M
    !^M
    create_cs,1,,1,jkp,kp_long,kp_shrt^M
    create_cs,0,,1,rpos_,phi_/2,0^M
    !^M
    l,kp_shrt,kp_long^M
    !^M
*elseif,cond_,eq,13,then^M
    !^M
    delta_=2*(asin((long_*sin((phi_/2)*rconv))/irad__))*dconv^M
    theta_=180-(phi_/2)-(delta_/2)^M
    !^M
    rpos_=sqrt((long_**2)+(irad__**2)-(2*long_*irad__*cos(theta_*rconv)))^M
    !^M
    create_cs,1,,1,jkp,kp_long,kp_shrt^M
    create_cs,0,,1,rpos_,phi_/2,0^M
    !^M
    l,kp_shrt,kp_long^M
    !^M
*elseif,cond_,eq,21,then^M
    !^M
    *if,dchk_,le,irad__,then^M
        theta1_=(acos(d_/(2*irad__)))*dconv^M
        theta2_=theta1_^M
        delta_=(asin((d_*sin(theta2_*rconv))/irad__))*dconv^M
        !^M
        theta_=theta1_+phi2_^M
        alpha_=theta2_+phi1_^M
        !^M
        rpos_=sqrt((long_**2)+(irad__**2)-(2*long_*irad__*cos(theta_*rconv)))^M
        beta_=(asin((irad__*sin(theta_*rconv))/rpos_))*dconv^M
        !^M
        create_cs,1,,1,jkp,kp_shrt,kp_long^M
        create_cs,0,,1,rpos_,phi_-beta_,0^M
        !^M
        l,kp_shrt,kp_long^M
    *elseif,dchk_,gt,irad__,then^M
        dl__=shrt_*sin((180-phi_)*rconv)^M
        delta_=(acos((irad__-dl__)/irad__))*dconv^M
        !^M
        d_=2*irad__*sin((delta_/2)*rconv)^M
        phi2_=(asin((shrt_*sin(phi_*rconv))/d_))*dconv^M
        !^M
        phi1_p_=180-phi2_-phi_^M
        long_p_=(d_*(sin(phi1_p_*rconv)))/(sin(phi_*rconv))^M
        !^M
        kl,dir_lng*ln_long,long_p_/long_^M
        get_max_entity^M
        !^M
        create_cs,1,,0,km,jkp,kp_shrt^M
        create_cs,0,,1,0,irad__,0^M
        !^M
        l,km,kp_shrt^M
    *endif^M
    !^M
*elseif,cond_,eq,22,then^M
    !^M
    *if,dchk_,le,irad__,then^M
        theta1_=(acos(d_/(2*irad__)))*dconv^M
        theta2_=theta1_^M
        delta_=(asin((d_*sin(theta2_*rconv))/irad__))*dconv^M
        !^M
        theta_=theta1_+phi2_^M
        alpha_=theta2_+phi1_^M
        !^M
        rpos_=sqrt((long_**2)+(irad__**2)-(2*long_*irad__*cos(theta_*rconv)))^M
        beta_=(asin((irad__*sin(theta_*rconv))/rpos_))*dconv^M
        !^M
        create_cs,1,,1,jkp,kp_shrt,kp_long^M
        create_cs,0,,1,rpos_,phi_-beta_,0^M
        !^M
        l,kp_shrt,kp_long^M
    *elseif,dchk_,gt,irad__,then^M
        dl__=shrt_*sin((180-phi_)*rconv)^M
        delta_=(acos((irad__-dl__)/irad__))*dconv^M
        !^M
        d_=2*irad__*sin((delta_/2)*rconv)^M
        phi2_=(asin((shrt_*sin(phi_*rconv))/d_))*dconv^M
        !^M
        phi1_p_=180-phi2_-phi_^M
        long_p_=(d_*(sin(phi1_p_*rconv)))/(sin(phi_*rconv))^M
        !^M
        kl,dir_lng*ln_long,long_p_/long_^M
        get_max_entity^M
        !^M
        create_cs,1,,0,km,jkp,kp_shrt^M
        create_cs,0,,1,0,irad__,0^M
        !^M
        l,km,kp_shrt^M
    *endif^M
    !^M
*elseif,cond_,eq,23,then^M
    !^M
    *if,dchk_,le,irad__,then^M
        theta1_=(acos(d_/(2*irad__)))*dconv^M
        theta2_=theta1_^M
        delta_=(asin((d_*sin(theta2_*rconv))/irad__))*dconv^M
        !^M
        theta_=theta1_+phi2_^M
        alpha_=theta2_+phi1_^M
        !^M
        rpos_=sqrt((long_**2)+(irad__**2)-(2*long_*irad__*cos(theta_*rconv)))^M
        beta_=(asin((irad__*sin(theta_*rconv))/rpos_))*dconv^M
        !^M
        create_cs,1,,1,jkp,kp_shrt,kp_long^M
        create_cs,0,,1,rpos_,phi_-beta_,0^M
        !^M
        l,kp_shrt,kp_long^M
    *elseif,dchk_,gt,irad__,then^M
        dl__=shrt_*sin((180-phi_)*rconv)^M
        delta_=(acos((irad__-dl__)/irad__))*dconv^M
        !^M
        d_=2*irad__*sin((delta_/2)*rconv)^M
        phi2_=(asin((shrt_*sin(phi_*rconv))/d_))*dconv^M
        !^M
        phi1_p_=180-phi2_-phi_^M
        long_p_=(d_*(sin(phi1_p_*rconv)))/(sin(phi_*rconv))^M
        !^M
        kl,dir_lng*ln_long,long_p_/long_^M
        get_max_entity^M
        !^M
        create_cs,1,,0,km,jkp,kp_shrt^M
        create_cs,0,,1,0,irad__,0^M
        !^M
        l,km,kp_shrt^M
    *endif^M
    !^M
*endif^M
!^M
init_entity_num^M
!^M
ksel,s,kp,,jkp^M
lslk,s,0^M
lsel,a,line,,lm^M
lglue,all^M
!^M
ksel,s,kp,,jkp^M
lslk,s,0^M
ldele,all,,,1^M
!^M
init_entity_num^M
!^M
lplot^M
!^M
*set,irad__,^M
*set,ln1__,^M
*set,ln2__,^M
*set,cond_,^M
*set,phi_,^M
*set,long_,^M
*set,shrt_,^M
*set,ang_lns,^M
*set,lng_long,^M
*set,lng_shrt,^M
*set,jkp,^M
*set,ln_long,^M
*set,ln_shrt,^M
*set,kp_long,^M
*set,kp_shrt,^M
*set,kplong_1,^M
*set,kplong_2,^M
*set,kpshrt_1,^M
*set,kpshrt_2,^M
*set,d_,^M
*set,phi1_,^M
*set,phi2_,^M
*set,thetachk,^M
*set,dchk_,^M
*set,dl__,^M
*set,dir_lng,^M
*set,dir_sht,^M
*set,beta_,^M
*set,alpha_,^M
*set,theta_,^M
*set,theta1_,^M
*set,theta2_,^M
*set,delta_,^M
!^M
*if,prkey_,eq,1,then^M
    /go^M
*endif^M