Trigonometry related to Archery

  • Thread starter Thread starter MstWntd
  • Start date Start date
  • Tags Tags
    Trigonometry
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 6K views
MstWntd
Messages
7
Reaction score
0
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:

[tex]x(t) = (v_{0} cos q) t[/tex]

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

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, I am 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 :rolleyes:

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

[tex]Maximum Height = (v_{0}2 sin2 q )/ (2g)[/tex]

I don't understand the sin2 thing, do we square the sin of q?

Thats all I have, any help is appricated.
 
Last edited:
Physics news on Phys.org
Welcome to PF.

MstWntd said:
[tex]x(t) = (v_{0} cos q) t[/tex]
Correct.

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

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

The above is supposed to give me the new X and Y values. I can't seem to work it properly.
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.

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

[tex]Maximum Height = (v_{0}2 sin2 q )/ (2g)[/tex]

I don't understand the sin2 thing, do we square the sin of q?

Nope, it's taking the sine of (2*q). v02 is squared though.
 
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 [tex]v_x = V_{max}cos(\theta)[/tex] and the y-component [tex]v_y = V_{max}sin(\theta)[/tex]. 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:
vy = vy - gravity
To calculate where the arrow is
Code:
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:
arrowRot = ATAN( vy / vx )

This is SUPER easy to code, and just fiddle with your gravity constant until it "feels" right.
 
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 I am not entirely certain), hence I will be re-writing the code.

minger, I will look into 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!