1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Having problems calculating Y vs X of projectile

  1. Jan 6, 2012 #1
    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. jcsd
  3. Jan 6, 2012 #2

    Doc Al

    User Avatar

    Staff: Mentor

    Tan(43°) isn't negative. (Make sure your code uses degrees, not radians. Or convert to radians.)

    That looks OK to me. Plug in some values by hand to check it.
     
  4. Jan 6, 2012 #3
  5. Jan 6, 2012 #4
    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.
     
  6. Jan 6, 2012 #5
    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?
     
  7. Jan 6, 2012 #6
    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);
     
  8. Jan 6, 2012 #7

    jtbell

    User Avatar

    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.
     
  9. Jan 6, 2012 #8
    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook