#Given
import math
tou = 25 #MPa, shear stress
sigma1 = 50 #MPa, stress
sigma2 = 80 #MPa
phi = 30*(math.pi/180.0)
# Calculations
sigma_x1 = (sigma1*math.cos(phi)*math.cos(phi))- (tou*math.cos(phi)*math.sin(phi)) - (sigma2*math.sin(phi)*math.sin(phi))- (tou*math.sin(phi)*math.cos(phi))
tou1 = (sigma1*math.cos(phi)*math.sin(phi))+ (tou*math.cos(phi)*math.cos(phi)) + (sigma2*math.sin(phi)*math.cos(phi))- (tou*math.sin(phi)*math.sin(phi))
sigma_x2 = (tou*math.cos(phi)*math.sin(phi))- (sigma2*math.cos(phi)*math.cos(phi)) + (tou*math.sin(phi)*math.cos(phi))+ (sigma1*math.sin(phi)*math.sin(phi))
tou2 = (tou*math.cos(phi)*math.cos(phi))+ (sigma2*math.cos(phi)*math.sin(phi)) - (tou*math.sin(phi)*math.sin(phi))+ (sigma1*math.sin(phi)*math.cos(phi))
#Display
print"The normal stress component in the x diection is = ",round(sigma_x1,1),"MPa"
print" The shear stress component in the x diection is = ",round(tou1,1),"MPa"
print" The normal stress component in the y diection is = ",round(sigma_x2,1),"MPa"
print" The shear stress component in the y diection is = ",round(tou2,1),"MPa"
#Given
import math
phi = -30*(math.pi/180) #angle
theta = 60*(math.pi/180)
sigma_x = -80 #MPa
sigma_y = 50 #MPa
tou_xy = -25 #MPa
#Plane CD
sigma_x1 = (sigma_x+sigma_y)/2 + ((sigma_x-sigma_y)*math.cos(2*phi))/2 + (tou_xy*math.sin(2*phi)) #Eqn 9.1
tou_xy1 = ((-(sigma_x - sigma_y)*math.sin(2*phi))/2) + (tou_xy*math.cos(2*phi)) #Eqn 9.2
#Plane BC
sigma_x2 = (sigma_x+sigma_y)/2 + ((sigma_x-sigma_y)*math.cos(2*theta))/2 + (tou_xy*math.sin(2*theta)) #Eqn 9.1
tou_xy2 = (-(sigma_x - sigma_y)*math.sin(2*theta))/2 + tou_xy*math.cos(2*theta) #Eqn 9.2
#Display
print'The normal stress of plane CD inclined at 30 degrees = ',round(sigma_x1,1),"MPa"
print'The shear stress of plane CD inclined at 30 degrees = ',round(tou_xy1,1),"MPa"
print'The normal stress of plane BC inclined at 60 degrees = ',round(sigma_x2,1),"MPa"
print'The shear stress of plane BC inclined at 60 degrees = ',round(tou_xy2,1),"MPa"
#Given
sigma_x = -20 #MPa, stress
sigma_y = 90 #MPa
tou_xy = 60 #MPa
#Orientation of Element
import math
theta_p2 = math.atan((2*tou_xy)/(sigma_x - sigma_y))
theta_p2 = theta_p2/2.0
theta_p1 = (180+2*theta_p2)/2.0
#Principal Stresses
sigma1 = ((sigma_x+sigma_y)/2.0)+(math.sqrt(((sigma_x - sigma_y)/2.0)**2 + tou_xy**2))
sigma2 = ((sigma_x+sigma_y)/2.0)- math.sqrt(((sigma_x-sigma_y)/2.0)**2 + tou_xy**2)
sigma_x2 = ((sigma_x+sigma_y)/2.0)+ (((sigma_x-sigma_y)/2.0)*math.cos(2*theta_p2)) + (tou_xy*math.sin(2*theta_p2))
#Display
print"The first principal stress is = ",round(sigma1,1),"MPa"
print"The second principal stress is = ",round(sigma2,1),"MPa"
print'The normal stress acting on the 23.7 degrees plane = ',round(sigma_x2,1),"MPa"
#Given
sigma_x = -20.0 #MPa, stress along x
sigma_y = 90.0 #MPa stress along y
tou_xy =60.0 #Mpa, shear stress
#Calculation
#Orientation of Element
import math
theta_s2 = math.atan(-(sigma_x - sigma_y)/(2*tou_xy))
theta_s2 = theta_s2/2.0
theta_s1 = math.pi + 2*theta_s2
theta_s1 = theta_s1/2.0
#Maximum in plane Shear Stress
tou_max = (math.sqrt(((sigma_x - sigma_y)/2.0)**2 + tou_xy**2))
tou_xy1 = -(sigma_x - sigma_y)*(math.sin(2*theta_s2))/2.0 + (tou_xy*math.cos(2*theta_s2))
#Average Normal Stress
sigma_avg = (sigma_x+sigma_y)/2
#Display
print"The maximum in-plane shear stress is = ",round(tou_xy1,1),"MPa"
print"The average normal stress is = ",round(sigma_avg,0),"MPa"
#Given
sigma_x = -12 #ksi, stress along x
sigma_y = 0
tou_xy = -6 #ksi, stress along xy
#Calculation
#Construction of the circle
import math
sigma_avg = (sigma_x+sigma_y)/2.0
R = sqrt((-sigma_x+sigma_avg)**2 + (tou_xy)**2)
#Principal Stresses
sigma2 = -R+sigma_avg
sigma1 = R+sigma_avg
theta_p2 = math.atan((-tou_xy)/(-sigma_x+sigma_avg))
theta_p2 = theta_p2/2*(180/math.pi)
#Display
print'The first principal stress is = ',round(sigma1,2),"ksi"
print'The second principal stress is = ',round(sigma2,2),"ksi"
print'The direction of the principal plane is = ',theta_p2,"degree"
#Given
sigma_x = -20.0 #MPa
sigma_y = 90.0 #MPa
tou_xy = 60.0 #MPa
#Construction of the circle
import math
sigma_avg = (sigma_x+sigma_y)/2
R = math.sqrt(((sigma_x-sigma_avg))**2 + (tou_xy)**2)
#Maximum In plane Shear Stress
tou_max = R
theta_s1 = math.atan(-(sigma_x - sigma_avg)/(tou_xy))
theta_s1 = theta_s1/2.0*(180/math.pi)
#Display
print'The maximum in-plane shear stresses are = ',round(tou_max,1),"MPa"
print'The second principal stress = ',sigma_avg,"MPa"
print'The orientation of the element is = ',round(theta_s1,1),"degree"
#Calculate normal stress and shear stress
#Given
sigma_x = -8.0 #MPa
sigma_y = 12.0 #MPa
tou_xy = -6.0 #Mpa
#Construction of the circle
import math
sigma_avg = (sigma_x+sigma_y)/2.0
R = math.sqrt( 10**2 + tou_xy**2)
#Stresses on 30 degree element
phi = math.atan(6/10.0)
psi = (math.pi/3.0) - phi
#On face BD
sigma_x1 = 2 - (R*math.cos(psi))
tou_xy1 = (R*math.sin(psi))
#On face DE
sigma_x2 = 2 + (R*math.cos(psi))
tou_xy2 = -(R*math.sin(psi))
#Display
print'The normal stress on plane BD inclined at 30 degrees is = ',round(sigma_x1,1),"ksi"
print'The normal stress on plane DE inclined at 60 degrees is = ',round(sigma_x2,1),"ksi"
print'The shear stress is = ',round(tou_xy1,1),"ksi"
print'The shear stress is = ',round(tou_xy2,1),"ksi"
#Given
sigma_max = 32 #MPa
sigma_min = 0 #MPa
sigma_int = 16 #MPa
#Calculation
tou_max = (sigma_max - sigma_min)/2
sigma_avg = (sigma_max + sigma_min)/2
tou_in_plane = (sigma_max - sigma_int)/2
sigma_avg2 = sigma_avg + (tou_in_plane)
#Display
print 'The normal shears tress is', sigma_avg,"MPa"
print'The maximum absolute shear stress = ',tou_max,"MPa"
#Given
tou = 40 #psi
sigma = -20 #psi
#Calculation
#Principal Stresses
import math
sigma_avg = sigma/2
R = sqrt( (-sigma + sigma_avg)**2 + tou**2)
sigma_max = sigma_avg + R
sigma_min = sigma_avg - R
theta = math.atan(tou/(-sigma+sigma_avg))
theta = theta/2
#Absolute Maximum Shear Stress
tou_max = (sigma_max - sigma_min)/2
sigma_avg = (sigma_max + sigma_min)/2
#Display
print'The prinicpal stresses at the point are ',round(sigma_max,2),"psi and",round(sigma_min,1),"psi"
print'The absolute maximum shear stress at the point ',round(tou_max,1),"psi"