# Trigonometry related to Archery

1. Nov 20, 2008

### MstWntd

Intro:
Hello, I have spent the last four or so days searching google and this forum and as rich as both are in information and helping. I have found it very hard to get anywhere.

Basically I haven't done any Maths/Physics related courses and as a result I am totally stumpped on my Games Technology Coursework.

Problem:
I am building a 3D game in C++ using OpenGL. I use a Bow and Arrow in this game.

I need to calculate the arc the Arrow will make, the maximum height it will reach, at what time (in milliseconds) it will hit the target.

By arc I mean, I would need to calculate its new X, Y and maybe X Rotation over the time its traveling.
So then I can render the Arrow in its new coorodinates, thus giving it the apperence of flight.

I hope I am making sense!

Attempted Solutions:
Suppose that the projectile starts at (0,0).
Suppose that the initial velocity of the projectile is v0.
X is the horizontal direction, and Y is the vertical direction.
Then, the distance in the x and y direction over time t is:

$$x(t) = (v_{0} cos q) t$$

$$y(t) = (v_{0} sin q) t – (gt^{2})/2$$

The above is supposed to give me the new X and Y values. I can't seem to work it properly.
Either the equation is wrong or my Game World has warped coordinates, Im so ill-experienced I can't even tell!

It might help if I understood the equation more. Also the course head will be checking our physics "engine" tommrow :uhh:

I have an equation for the Maximum height as well..

$$Maximum Height = (v_{0}2 sin2 q )/ (2g)$$

I dont understand the sin2 thing, do we square the sin of q?

Thats all I have, any help is appricated.

Last edited: Nov 20, 2008
2. Nov 20, 2008

### Redbelly98

Staff Emeritus
Welcome to PF.

Correct.

Okay, I see you did include a "-" in there, but it's not displaying properly:
$$y(t) = (v_{0} sin q) t - (gt^{2})/2$$
is correct.

One thing you may not be aware of, most programming languages assume "radians" units for angles when they do trig functions. Are your q's in degrees or radians?

If that's not the problem, can you give some sample values for t, x, y, q, v0, and g? Then we can try to figure out why you're getting the wrong answer even though the equations are correct.

Nope, it's taking the sine of (2*q). v02 is squared though.

3. Nov 20, 2008

### minger

I've written some flash games back in the day, and I find that typically it's much easier to pseudo-simulate real-world physics and you can obtain much easier results.

For example, your starting arrow velocity will remain constant. Better yet, you can give it some function of string tension, or "power". Now, let the user choose an angle.

Now, the x-component of your velocity will simply be $$v_x = V_{max}cos(\theta)$$ and the y-component $$v_y = V_{max}sin(\theta)$$. You keep your x-component to the velocity constant. At this point you will neglect air resistance, so don't worry about it.

Now, you will simulate gravity by subtracting a certain amount from the y-velocity. So, each frame, just:
Code (Text):

vy = vy - gravity

To calculate where the arrow is
Code (Text):

x = x + vx
y = y + vy

Since the game will 3D, you can use z as the vertical direction, and x/y for directionality. To keep track of the arrow "rotation" just use the angle that the components of the velocity make with the ground. e.g.
Code (Text):

arrowRot = ATAN( vy / vx )

This is SUPER easy to code, and just fiddle with your gravity constant until it "feels" right.

4. Nov 24, 2008

### MstWntd

Hi,

Sorry for the late reply and thank you for the help!

On Friday before the 2nd submission, I found a few things I was doing wrong. One thing was that my gravity was a positive number, this meant my arc was present but the Arrow would never decent! There was also something to do with the initial volocity and how I increased it.

But one thing is for certain, my Game World has improper fundamentals (ok im not entirely certain), hence I will be re-writing the code.

minger, I will look in to your advice after the re-write, I haven't put ANYTHING in classes, its all glued together with gobal methods and public variables!

One thing is note worthy, the Arrow DOES behave correctly on occasion, but only with certain numbers. If all else fails then I'll trouble you guys with some sample numbers and see where we get.

Thank you both, wish me luck!