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

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

1. ## 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. ## 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. ## 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.