Having problems calculating Y vs X of projectile

1. Jan 6, 2012

gaate

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

2. Jan 6, 2012

Staff: Mentor

That looks OK to me. Plug in some values by hand to check it.

3. Jan 6, 2012

4. Jan 6, 2012

rollcast

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.

5. Jan 6, 2012

gaate

I dont 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?

6. Jan 6, 2012

rollcast

In java when you use tan(x) it calculates using x as 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.

7. Jan 6, 2012

Staff: Mentor

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.

8. Jan 6, 2012

gaate

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 wierd to me.