
/***************************************************************
File:   2ds.c - 2-Dimensional Stress Equation
Desc:   Given any two orthogonal stesses, åx and åy and the
        shear stress, çxy, the stress transformation is calculated
        to give the maximum and minimum principal stresses.  The
        rotation of the stress element from the +x-axis to å1 or
        å2 is also calculated.  CCW is assumed to be positive for
        this angle (í) and for shear directions.
        The maximum shear stress is correctly calculated from the
        triaxial stress state.

David Edwards <edwards@dee-engineering.com>
***************************************************************/

#include <stdio.h>
#include <math.h>
#include <mathext.h>
#include <conio.h>

void input (char *str, int *addr)
{
        printf(str);
        scanf("%lf", addr);
}

main()
{
    double sx,sy,tauxy,sa,sb,phi,s1,s2,s3,sp,tau1,taumax,save;

    input("\n  Tensile Stress, åx [ksi]: ",&sx);
    input("  Tensile Stress, åy [ksi]: ",&sy);
    input("  Shear Stress, çxy  [ksi]: ",&tauxy);
    rpc(.5*(sx-sy),tauxy,&tau1,&phi);
    save=.5*(sx+sy);
    sa=save+tau1;
    sb=save-tau1;
    if (sa >= 0.0) {
        if (sb >= 0.0) {
            s1=sa;
            s2=sb;
            s3=0.0;
            taumax=fabs(.5*s1);
        }
        else {
            s1=sa;
            s2=0.0;
            s3=sb;
            taumax=fabs(.5*(s1-s3));
        }

        printf("\n  Angle from the +x-axis to å1 (principal direction)"
               " [deg]: %6.1lf\n",phi*90.0/M_PI);
    }
    else {
            s1=0.0;
            s2=sa;
            s3=sb;
            taumax=fabs(.5*s3);
            printf("\n  Angle from the +x-axis to å2 (principal direction)"
                   " [deg]: %6.1lf\n",phi*90.0/M_PI);
    }

    sp=sqrt(sa*sa-sa*sb+sb*sb);

    printf("\n  Maximum principal stress,      å1 [ksi]: %10.2lf\n",s1);
    printf("  Intermediate principal stress, å2 [ksi]: %10.2lf\n",s2);
    printf("  Minimum principal stress,      å3 [ksi]: %10.2lf\n",s3);
    printf("\n  Maximum shear stress,        çmax [ksi]: %10.2lf\n",taumax);
    printf("\n  von Mises stress,              å' [ksi]: %10.2lf\n",sp);

}
