--Originally published at Hector Martinez Alcantara
Today I finished a program that can tell you the sum of three, or as many vectors as you want and the vector that balance the system.
There is a menu that shows two options.
In the case A you type 3 forces with their angles, and then the program shows the sum of components in X, components in Y, the resulting vector with its angle, and the vector with the angle that balances the system.
In the case B you type how many forces you want, then you type the forces with their angles, and then the program shows the sum of components in X, components in Y, the resulting vector with its angle, and the vector with the angle that balances the system.
import math
#------------------SHOWS THE VECTOR AND IT'S COMPONENTS-----------------
def Vector(compx,compy):
magnr=math.hypot(float(compx), float(compy))
print("\nSumatoria de componentes en X " + str(compx))
print("Sumatoria de componentes en Y " + str(compy))
print("\nVector Resultante:")
if compx<0.0 and compy>0.0:
print("Segundo sector")
angr=math.degrees(math.atan(compy/compx)) + 180.0
elif compx<0.0 and compy<0.0:
print("Tercer sector")
angr=math.degrees(math.atan(compy/compx))+ 180.0
elif compx>0.0 and compy<0.0:
print("Cuarto sector")
angr=360+math.degrees(math.atan(compy/compx))
else:
print("Primer sector")
angr=math.degrees(math.atan(compy/compx))
print("La magnitud del vector resultante es "+ str(magnr) +"N")
print("El angulo del vector resultante es "+ str(angr) +"° del eje +x")
print("\nVector Complementario:")
if compx<0.0 and compy>0.0:
print("Cuarto sector")
angr= angr + 180.0
elif compx<0.0 and compy<0.0:
print("Primer sector")
angr= angr - 180
elif compx>0.0 and compy<0.0:
print("Segundo sector")
angr= angr - 180.0
else:
print("Tercer sector")
angr= angr + 180.0
print("La magnitud del vector complementario es "+ str(magnr) +"N")
print("El angulo del vector complementario es "+ str(angr) +"° del eje +x")
#--------------MAIN PROGRAM--------------------------------
y=0
while y!=1:
print("\nCasos:")
print("A) Tres fuerzas, encontrar la fuerza
Continue reading "Sum of vectors program" →