Trigonometry related to Archery

  • Thread starter Thread starter MstWntd
  • Start date Start date
  • Tags Tags
    Trigonometry
Click For Summary
The discussion centers on the challenges of implementing projectile motion for a bow and arrow in a 3D game using C++ and OpenGL. The user seeks to calculate the arrow's trajectory, including its arc, maximum height, and impact time, but struggles with the underlying physics equations. Key equations for horizontal and vertical motion are provided, with clarification on the use of radians for angles and the correct interpretation of the maximum height formula. The user realizes mistakes in their gravity implementation and initial velocity adjustments, indicating a need to rewrite their code for better structure. The conversation highlights the importance of simulating real-world physics for accurate game mechanics.
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:

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, 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..

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

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:
x(t) = (v_{0} cos q) t
Correct.

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

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.

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..

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

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 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:
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!
 
The book claims the answer is that all the magnitudes are the same because "the gravitational force on the penguin is the same". I'm having trouble understanding this. I thought the buoyant force was equal to the weight of the fluid displaced. Weight depends on mass which depends on density. Therefore, due to the differing densities the buoyant force will be different in each case? Is this incorrect?

Similar threads

Replies
11
Views
3K
Replies
42
Views
3K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
10
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 14 ·
Replies
14
Views
2K
  • · Replies 20 ·
Replies
20
Views
2K