1

I am trying to write program for projectile motion in Python, while entering the values of horizontal velocity and vertical velocity, I am getting the correct results if I enter definite constant values directly in the program.

But when I use the code such that the user the enter the value of angle in degrees, (Importing numpy as np, obviously), I am getting very small answers (for $45^{\circ}$ the value is coming as $-0.0001...$ instead of $40.8$ which is correctly showing when I enter the values of the components of velocity by hand in the program.

Here's my excerpt of the program for reference,

thetaVal = input("Please enter theta value in degrees: ")
theta_val = float(thetaVal)
t = theta_val *180/3.14

v_x0= v_0*np.cos(t)
v_y0= v_0*np.sin(t)

I can't figure out where am I going wrong with this, whether my conversion way is wrong or the code has some issues with the precedence of the statements, I really cant figure out.

Any help would be appreciated thanks!

mnuizhre
  • 169
  • 7

1 Answers1

1

Numpy's cos and sin functions take the angle in radians. To convert from degrees to radians, you would write

t = theta_val * 3.14 / 180

Or better yet,

t = np.radians(theta_val)

or equivalently

t = np.deg2rad(theta_val)
Kosaro
  • 365
  • 1
  • 12
  • Oh yes, guess I converting radians to degrees assuming that the sine would take the values in degrees too. Thanks! – mnuizhre Nov 26 '20 at 07:39