# Math Help - Getting an angle from a curve and a straight line

1. ## Getting an angle from a curve and a straight line

Ok, first things first. I'm a programmer, I'm actually working on a flash game and I'm always having a bad time trying to understand maths.

What I'm trying to create here is an archer autonomously firing on a target using the right angle. The problem is, I can't manage to get that angle. I've tried tons of stuff to no avail so I shall put this into a simple drawing.

I have two points, A and B. I have the distance, which is X as well as the curve, that forms a circle, this circle's diameter being Y. Now what I lack is, the angle between the line and the curve at point A (?).

Also, note that I'm not really good at maths, if at all. I may not understand complex terms and such.

Well this is it. Thanks to whoever solves this or tries solving it!

2. ## Re: Getting an angle from a curve and a straight line

Originally Posted by drak68
Ok, first things first. I'm a programmer, I'm actually working on a flash game and I'm always having a bad time trying to understand maths.

What I'm trying to create here is an archer autonomously firing on a target using the right angle. The problem is, I can't manage to get that angle. I've tried tons of stuff to no avail so I shall put this into a simple drawing.

I have two points, A and B. I have the distance, which is X as well as the curve, that forms a circle, this circle's diameter being Y. Now what I lack is, the angle between the line and the curve at point A (?).

Also, note that I'm not really good at maths, if at all. I may not understand complex terms and such.

Well this is it. Thanks to whoever solves this or tries solving it!

Why are you using a circular arc for the trajectory?

CB

3. ## Re: Getting an angle from a curve and a straight line

Unless you have, for some reason, decided you must use a semi-circular trajectory for your arrow, this is not so much a math problem as a physics problem. Physically, the trajectory, neglecting air resistance, is a parabola.

Neglecting air resistance, the only force on the arrow is gravity, straight downward. That means the arrow has a downward acceleration of -g (g= 9.81 approximately) and 0 horizontal accelration: $a_x=\frac{dv_x}{dt}= 0$ and $a_y= \frac{dv_y}{dt}= -g$ so $v_x= v_0cos(\theta)$ and $v_y= -gt+ v_0sin(\theta)$ where $v_0$ is the initial speed of the arrow and $\theta$ is the angle.

Now, $v_x= \frac{dx}{dt}= v_0cos(\theta)$ and $v_y= \frac{dy}{dt}= -gt+ v_0sin(\theta)$ so $x= v_0cos(\theta)t$ and $y= -\frac{g}{2}t^2+ v_0sin(\theta)t$ where I have taken the initial position of the arrow, the position of the archer, to be (0, 0). If you want other coordinates, add them.

To determine the angle, $\theta$, you need to know two things in advance- the initial velocity of the arrow, $v_0$, and the distance from the archer to the target, X. Solve both $x= v_0cos(\theta)t= X$ and $y= -gt^2+ v_0sin(\theta)t= 0$ for t. That's easy: from the first equation, $t= \frac{X}{v_0cos(\theta)}$ and from the second, $t(-gt+ v_0sin(\theta))= 0$ so either t= 0 (the arrow was fired from height 0 so we get the initial time as a solution) or $t= \frac{v_0sin(\theta)}{g}$. Since you want the arrow to be at (X, 0) for one t, those must be the same: $\frac{X}{v_0cos(\theta)}= \frac{v_0sin(\theta)}{g}$ which is the same as $sin(\theta)cos(\theta)= \frac{gX}{v_0^2}$.

You can simplify that using the trig identity $sin(2\theta)= 2 sin(\theta)cos(\theta)$ so that $sin(\theta)cos(\theta)= \frac{1}{2}sin(2\theta)= \frac{gX}{v_0^2}$. That is, $\theta= \frac{1}{2}arcsin\left(\frac{gX}{2v_0^2}\right)$

Note that since sine cannot be larger than 1, if X is too large or $v_0$ is not large enough, this may be impossible- X is "out of range". Also, it will typically happen that there are two angles, between 0 and 90 degrees, that satisfy that equation.

If you really want to use a circular trajectory, you can do this:
Let r be the radius of the circle (so that Y= 2r). Drawing radii from the center of the circle to the endpoints of X, we have an isosceles triangle with two sides of length r and one of length X. Applying the cosine rule to that triangle, The angle at the center of the circle, $\theta$, satisfies $X^2= 2r^2(1- cos(\theta))$ so that $\theta= arccos(1- \frac{X^2}{2r^2})$. Writing the two "base" angles as $\phi$, we have, of course, $2\phi+ \theta= 2\pi$ so that $\phi= \pi- \frac{\theta}{2}$. The angle the circle makes with line X is the complement of that: $\frac{\pi}{2}- \phi= \frac{\theta}{2}- \frac{\pi}{2}= \frac{1}{2}arccos(1- \frac{X^2}{2r^2})- \frac{\pi}{2}$.

That is in radians, of course.

4. ## Re: Getting an angle from a curve and a straight line

The (parabola) trajectory is documented in wikipedia:

The angle is documented as:
$\theta = {1\over 2}\arcsin({gX \over v_o^2})$
where $g=9.81 {m \over s^2}$ and $v_o$ is the initial speed.

5. ## Re: Getting an angle from a curve and a straight line

I've been using a circle because the arrow DOES makes a circle in the game. There is no gravity applied to it or anything, just a constant rotation and acceleration towards its current angle, which makes circles. I know its clearly not the best way to simulate projectiles but I felt like messing with gravity wasn't really a good idea, or just really time consuming for just a small part of the game.

As for $\theta = {1\over 2}\arcsin({gX \over v_o^2})$, it didn't work, probably because I'm not using gravity at all, or flash is just doing wierd stuff when trying to make complex equations.

6. ## Re: Getting an angle from a curve and a straight line

All right.

The angle that you ask for is:
$\theta = 90^o - \arccos({X \over Y})$

7. ## Re: Getting an angle from a curve and a straight line

Wow. That actually worked. Thanks a lot I've been having headaches over this for weeks!