Having problems calculating Y vs X of projectile

  • Thread starter Thread starter gaate
  • Start date Start date
  • Tags Tags
    Projectile
AI Thread Summary
The discussion revolves around issues with a Java program designed to graph the trajectory of a projectile, specifically the calculation of y versus x coordinates. The user encounters problems when using the tangent function for angles, particularly noting that the graph behaves incorrectly for angles like 43 degrees. It is clarified that Java's trigonometric functions operate in radians, which necessitates converting degrees to radians before using them in calculations. The user successfully resolves the issue by implementing the conversion, leading to the program functioning correctly. Understanding the radians versus degrees distinction is crucial for accurate trigonometric calculations in programming.
gaate
Messages
4
Reaction score
0
I am making a java program and part of it is to graph the path of a projectile x vs y.

The problem i have is that when i use this equation, it messes up the rest of the graph, whenever tan of the angle is negative, so say for 45 degrees the program works fine, but for 43 degrees the graph is just a strait line.

It seems however that this equation would do this regardless of it being in a program. So my equation must be wrong. Here is is out of code.

H + (x * tan(a)) - ((9.8 * x^2) / (2 * (V * cos a)^2))

in code

points[count] = h + (count * tan(a)) - ((9.8 * Math.pow(count,2)) / (2 * Math.pow((tVel * cos(a)),2)));

What with my equation is off?


Also,
If anyone would be feeling Generous enough to help me test it out, just check some math, i would be forever gratefull.

http://www.mediafire.com/?r2e0e4ha57u13uq
 
Physics news on Phys.org
gaate said:
The problem i have is that when i use this equation, it messes up the rest of the graph, whenever tan of the angle is negative, so say for 45 degrees the program works fine, but for 43 degrees the graph is just a strait line.
Tan(43°) isn't negative. (Make sure your code uses degrees, not radians. Or convert to radians.)

It seems however that this equation would do this regardless of it being in a program. So my equation must be wrong. Here is is out of code.

H + (x * tan(a)) - ((9.8 * x^2) / (2 * (V * cos a)^2))
That looks OK to me. Plug in some values by hand to check it.
 
In java the Trigonometry methods use radians.

There is a toradians method that will convert from degrees to radians for you

Edit.

You got there before me.
 
In java the Trigonometry methods use radians.

There is a toradians method that will convert from degrees to radians for you

Edit.

You got there before me.

I don't understand which was it is when you say that the trig equations "use" radians.

are you saying i need to convert the angle that the user inputs to radians before it is put through the equation?

or convert what comes out of tan(a) into degrees?
 
In java when you use tan(x) it calculates using x as radians.

the toradians method will convert a degrees value into radians.

eg. if you have a variable called "degs" you can create a new variable "rads" which is the no. of degrees converted into radians.

rads = Math.toRadians(degs);
 
What "comes out of tan(a)" is not an angle. You have to convert what goes into tan(a), that is, a. (from degrees to radians)

Conversely, if you use any of the inverse trig functions to get an angle, it will be given in radians, which you need to convert to degrees if you want to see it in degrees. Of course, if you're just going to use the angle in another trig function later in the program, you should just leave it in radians.
 
rollcast said:
In java when you use tan(x) it calculates using x as radians.

the toradians method will convert a degrees value into radians.

eg. if you have a variable called "degs" you can create a new variable "rads" which is the no. of degrees converted into radians.

rads = Math.toRadians(degs);

Thank you so much, i tried it while i was waiting for a response and it fixed my whole program.

I understood that something was not right with that was being used (radians vs degrees) but I never would have guessed that the trig functions take radians, that seems weird to me.
 
Back
Top