1 Attachment(s)

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.

Attachment 23128

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!

Also, if you need more information about my little problem just ask away as I'm aware that the info I gave may not be adequate.

Re: Getting an angle from a curve and a straight line

Quote:

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.

Attachment 23128
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!

Also, if you need more information about my little problem just ask away as I'm aware that the info I gave may not be adequate.

Why are you using a circular arc for the trajectory?

CB

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: and so and where is the initial speed of the arrow and is the angle.

Now, and so and 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, , you need to know two things in advance- the initial velocity of the arrow, , and the distance from the archer to the target, X. Solve both and for t. That's easy: from the first equation, and from the second, so either t= 0 (the arrow was fired from height 0 so we get the initial time as a solution) or . Since you want the arrow to be at (X, 0) for one t, those must be the same: which is the same as .

You can simplify that using the trig identity so that . That is,

Note that since sine cannot be larger than 1, if X is too large or 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, , satisfies so that . Writing the two "base" angles as , we have, of course, so that . The angle the circle makes with line X is the complement of that: .

That is in radians, of course.

Re: Getting an angle from a curve and a straight line

The (parabola) trajectory is documented in wikipedia:

The angle is documented as:

where and is the initial speed.

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 http://latex.codecogs.com/png.latex?...0v_o%5E2%7D%29, 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.

Re: Getting an angle from a curve and a straight line

All right.

The angle that you ask for is:

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!