Having problems calculating Y vs X of projectile

  • Thread starter gaate
  • Start date
  • Tags
    Projectile
In summary, the programmer was having trouble with an equation that was supposed to graph the path of a projectile, and they were not sure what was wrong. The equation used degrees instead of radians, and the toradians method was able to convert degrees into radians.
  • #1
gaate
4
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
  • #2
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.
 
  • #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.
 
  • #5
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?
 
  • #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);
 
  • #7
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
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.
 

Related to Having problems calculating Y vs X of projectile

1. How do I calculate the initial velocity of a projectile?

The initial velocity of a projectile can be calculated using the formula v = √(2gh), where v is the initial velocity, g is the acceleration due to gravity (9.8 m/s²), and h is the initial height of the projectile.

2. What is the difference between horizontal and vertical velocity in projectile motion?

Horizontal velocity is the constant speed at which a projectile travels in the horizontal direction, while vertical velocity is the speed at which it travels in the vertical direction. In projectile motion, the two velocities are independent of each other.

3. How do I calculate the time of flight for a projectile?

The time of flight for a projectile can be calculated using the formula t = 2v sin θ / g, where t is the time of flight, v is the initial velocity, θ is the angle of launch, and g is the acceleration due to gravity.

4. What is the maximum height reached by a projectile?

The maximum height reached by a projectile can be calculated using the formula h = v² sin² θ / 2g, where h is the maximum height, v is the initial velocity, θ is the angle of launch, and g is the acceleration due to gravity.

5. How do I account for air resistance in projectile motion calculations?

To account for air resistance, you can use the formula v = v₀ - gt, where v is the final velocity, v₀ is the initial velocity, g is the acceleration due to gravity, and t is the time of flight. This will give you a more accurate calculation for the projectile's trajectory in real-world scenarios where air resistance is present.

Similar threads

Replies
5
Views
1K
  • Introductory Physics Homework Help
Replies
6
Views
592
Replies
4
Views
1K
  • Introductory Physics Homework Help
Replies
19
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
19
Views
3K
  • Introductory Physics Homework Help
Replies
32
Views
1K
Replies
2
Views
632
Replies
11
Views
1K
  • Introductory Physics Homework Help
Replies
1
Views
1K
  • Introductory Physics Homework Help
Replies
8
Views
2K
Back
Top