Finding the release angle for projectile

233 Views Asked by At

Hello. I would like to create an game application for android platform that is similar like projectiles. I called it snowball machine. As you know regular projectiles has to hit the target on the ground which is dY=0.

The system that I would to create is going to be able to hit the target with different Target(X,Y) coordinates. The only variables that I will be able to know is Length of the arm and Target(X,Y) coordinates. With these variables I will be able to calculate the release angle(Theta).

I just posted blueprint of the system.

enter image description here

enter image description here

Note that cscθ returns the distance from the origin to the y-intercept of the tangent line, and secθ returns the distance from the origin to the x-intercept of the tangent line.

Let m represent slope: m=Δy/Δx=cscθ/secθ

this is so far good and understandable. But the problem is how am I going to know that my target slope and length of the arm's slope will be perpendicular. Can anyone help me with the equations of each lines slopes and finding the releasing angle? Thank you for your time.

1

There are 1 best solutions below

0
On

The diagram below should help explain my answer (apologies for the sub-optimal formatting)

enter image description here

We have point $(X2,Y2)$, which is where the tangent touches the circle. The line from the centre of the circle to point $(X2,Y2)$ has gradient $$\frac{Y2}{X2}=\tan(\theta)$$

We can express $X2$ and $Y2$ in terms of the length of the arm $L$ as follows:- $$X2=L\cos(\theta),Y2=L\sin(\theta)$$

Now the gradient of the red line (the trajectory of your projectile) will be $-\frac{1}{\tan(\theta)}$, as the product of the gradients of two perpendicular lines equals $-1$.

The gradient of the red line is also equal to $\frac{Y-Y2}{X-X2}$. So we have

$$\frac{Y-Y2}{X-X2}=-\frac{1}{\tan(\theta)}$$

Substituting in the values of $X2$ and $Y2$ in terms of $L$, we have

$$\frac{Y-L\sin(\theta)}{X-L\cos(\theta)}=-\frac{1}{\tan(\theta)}\Rightarrow Y\tan(\theta)-L\sin(\theta)\tan(\theta)=L\cos(\theta)-X$$

We need to solve the following equation $$Y\tan(\theta)-L\sin(\theta)\tan(\theta)-L\cos(\theta)+X=0$$

Multiplying throughout by $\cos(\theta)$ we have

$$Y\sin(\theta)-L\sin^2(\theta)-L\cos^2(\theta)+X\cos(\theta)=0$$

Simplifying results in (as $\sin^2(\theta)+\cos^2(\theta)=1$)

$$Y\sin(\theta)-L+X\cos(\theta)=0$$

Letting $u=\sin(\theta)$, we can form the following quadratic equation:- $$Yu-L+X\sqrt{1-u^2}=0\Rightarrow X^2(1-u^2)=L^2-2LYu+Y^2u^2\\\Rightarrow (Y^2+X^2)u^2-2LYu+(L^2-X^2)=0$$

Solving for $u$, we have $$u=\frac{2LY\pm\sqrt{4L^2Y^2-4(Y^2+X^2)(L^2-X^2)}}{2(Y^2+X^2)}=\frac{LY\pm X\sqrt{Y^2+X^2-L^2}}{(Y^2+X^2)}$$

Thus, to solve for angle $\theta$ in terms of the arm length $L$ and the target coordinates $(X,Y)$, we have

$$\theta=\arcsin\left\{\frac{LY\pm X\sqrt{Y^2+X^2-L^2}}{(Y^2+X^2)}\right\}$$