1
$\begingroup$

I am using the following formula to draw the trajectory of a javelin (this is very basic, I am not taking into consideration the drag, etc.).

  speedX = Math.Cos(InitialAngle) * InitialSpeed;   speedY = Math.Sin(InitialAngle) * InitialSpeed;   javelin.X = speedX * timeT;   javelin.Y = speedY * timeT - 0.5 * g * Math.Pow(timeT, 2); 

How do I know at what angle my javelin for a given timeT?

2 Answers 2

2

The velocity of the javelin is the first derivative of the position:

javelin.vx = speedX; javelin.vy = speedY - g * timeT 

Assuming a well-thrown javelin always points in the direction of travel, the angle can be found using the arctangent function:

javelin.angle = atan(javelin.vy / javelin.vx); 

If you are writing code, you can prevent a division by zero by using a version of arctangent that takes the rise and run as separate parameters:

javelin.angle = atan2(javelin.vy, javelin.vx); 
1

I am making the assumption that the javelin is pointed exactly in the direction of its motion. (This seems dubious, but may be a close enough approximation for your purposes).

The speed in the X direction is constant, but the speed in the Y direction is $\text{speedY} -g\cdot \text{timeT}$. So the direction of motion has angle $\text{angle}\theta$ from the positive X direction satisfying $\tan(\text{angle}\theta)=\frac{\text{speedY}-g\cdot\text{timeT}}{\text{speedX}}.$ If the initial angle is in $\left(0,\frac{\pi}{2}\right)$, then the angle always lies in $\left(-\frac{\pi}{2},\frac{\pi}{2}\right)$, and you can use the ordinary $\arctan$ function to get $\text{angle}\theta$.