Having problems calculating Y vs X of projectile

  • Context: Undergrad 
  • Thread starter Thread starter gaate
  • Start date Start date
  • Tags Tags
    Projectile
Click For Summary

Discussion Overview

The discussion revolves around a participant's difficulties in calculating the trajectory of a projectile in a Java program, specifically focusing on the relationship between the x and y coordinates. The scope includes programming, mathematical reasoning, and the application of trigonometric functions in projectile motion calculations.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant describes an issue where the graph of the projectile's path becomes a straight line for angles other than 45 degrees, suggesting a potential error in their equation.
  • Another participant points out that the tangent of 43 degrees is not negative and suggests checking if the code uses degrees instead of radians.
  • There is a discussion about Java's trigonometric functions, which use radians, and the need to convert degrees to radians before using them in calculations.
  • A participant explains how to convert degrees to radians using the Math.toRadians method in Java.
  • Clarification is provided that the input to the tangent function must be in radians, not degrees, and that the output of the tangent function is not an angle.
  • One participant expresses gratitude after implementing the suggested conversion, indicating that it resolved their programming issue.

Areas of Agreement / Disagreement

Participants generally agree on the need to convert degrees to radians for trigonometric calculations in Java, but there is some initial confusion regarding the handling of angles and the behavior of the tangent function.

Contextual Notes

The discussion highlights the importance of understanding the distinction between degrees and radians in programming, particularly in the context of trigonometric functions, but does not resolve all potential misunderstandings about the mathematical model used for projectile motion.

Who May Find This Useful

This discussion may be useful for programmers working with physics simulations, students learning about projectile motion, or anyone interested in the application of trigonometric functions in coding.

gaate
Messages
4
Reaction score
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
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.
 
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.
 
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?
 
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);
 
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.
 
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.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 11 ·
Replies
11
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K