Sign in to follow this  

Calculate position and angle of javelin exercise (my attempt)

Recommended Posts

Hello everybody, I am self-teaching myself game physics and currently I am reading a book called "Mathematics and Physics for game programmers" and I am at chapter 7 exercise 1 where one of the exercises ask:

Write a function javelin(throwAngle, throwSpeed, time) which calculates the position and angle of a javelin over time. The function should return a vector representing the position of the javelin at time time after firing and the angle it makes with the horizontal. During its flight, a javelin is more or less oriented along the tangent to the curve—that is to say, parallel to the velocity vector 

After giving it a go, this is what I managed to come up with:
 

 float Javelin(float ThrowAngle, float Velocity, float Acceleration, float Time)
{
	return ThrowAngle + Velocity * Time + Acceleration * Time * Time / 2.0f;
}



The function above is meant to return the position of the javelin after the throw, but I am not sure whether it is correct or not because the book does not contain the solution to this exercise (hence why I am posting). Do you think this looks alright? And if so, how can I obtain the angle?

Thank you so much for your help.

Share this post


Link to post
Share on other sites

Heya. 

I think you should read the question more carefully as you seem to have a mismatch in your attempt. The question says that your function should return a vector, which is something you're not doing. Also your function is taking in 4 arguments and the exercise is saying to compute using but three floats. With that said, you seem to be adding angle + distance^2 which I don't think is correct. You should probably look more into kinematic equations before you attempt this again. I recommend visiting this site (http://www.physicsclassroom.com/) and going through the first sections so you may have a better understanding of the motion of objects in 2D space. 

 

Good job on attempting the exercise though. :)  

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this