Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Putting Trajectory of a Projectile formula in Java form.

  1. #1
    Member
    Join Date
    Oct 2011
    Posts
    46
    My Mood
    Asleep
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Putting Trajectory of a Projectile formula in Java form.

    It's part of my assignment. Though, I keep getting different and negative numbers but I'm not sure why. I'm supposed to use the formula:

    V^2*sin(2*A)
    g

    Where V = launch speed A = Angle (A is actually supposed to be theta) and g = gravity.

    Instead of using meters, I used the feet conversion to go from Miles Per Hour to feet because the output has to be in feet. So I had to multiply the result by the number of feet in a mile. I also used the force of Earths gravity in feet (32.2). First I did the formula in Java by doing:

    //Pretend that mySpeed[row] = 20 MPH and myAngle[col] = 25 degrees
     
    variable = (Math.pow(mySpeed[row],2) * Math.sin(2 * myAngle[col]) / 32.2) * 5280;

    The output seems to be -17209. But I get 50,244.9 on the calc. And the debugger won't get that specific for me so I can't pinpoint where things go wrong. Can someone spot what I did wrong. I assume it's my parenthesis.


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Putting Trajectory of a Projectile formula in Java form.

    the force of Earths gravity in feet.
    My eyes!

    Should the argument to Math.sin be in degrees? It might be worth checking the API docs.

  3. The Following User Says Thank You to Sean4u For This Useful Post:

    mwebb (March 2nd, 2012)

  4. #3
    Member
    Join Date
    Oct 2011
    Posts
    46
    My Mood
    Asleep
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Putting Trajectory of a Projectile formula in Java form.

    Hmm, interesting point. Well I am supposed to use the toRadians() method but I haven't figured out what to use that for. I'll try that.

    EDIT: Well, turned out I am getting a closer figure when using that method. This time the output was 50559. So I think that data is close enough to be considered true. My teacher isn't so concerned about data accuracy. Well, good job mate! I overlooked something.

Similar Threads

  1. Method is not initiating formula
    By CrimsonFlash in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 22nd, 2011, 09:19 PM
  2. Need help putting GUI in program!
    By greyfox175 in forum AWT / Java Swing
    Replies: 5
    Last Post: May 4th, 2011, 09:55 PM
  3. Acessor Method Problems for Projectile Motion
    By Kaiki in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 28th, 2011, 08:01 PM
  4. Java - Button Actions on Form --Please help
    By Cami7 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 24th, 2011, 01:31 PM
  5. Java Swing :Back Button from one form to another form
    By srinivasan_253642 in forum AWT / Java Swing
    Replies: 1
    Last Post: December 26th, 2009, 09:51 AM