Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Calculate throw angle to have the curve cross a certain point

  1. Jul 11, 2012 #1
    Hello,
    I'm not sure if this is the right section because this is somewhat of a hybrid of math and physics.
    Say I have a ball in 3D space, its initial position and its' initial acceleration. Furthermore I have another point in 3D space which I want the ball to pass through, if possible. The gravity is 9.81 m/s2. Friction etc is of no importance.
    How could I calculate the initial angle or tangent of this curve, so that the ball would hit the point , if possible?

    In case that just now wasn't all that clear, I'll explain my problem in my current context. I'm a game developer and want players to be able to click at a point and jump to it the next time they hit space. However, they can charge their jump and if they are very close to the target and have charged up the jump a lot they must jump in a high arc to hit the target sqarely. If the target is too far away, the player should jump using 45%, but I can program by comparing the distance. All I need is a formula which takes the initial acceleration and the gravity and calculates which angle is needed to hit that point

    I'm sorry to bother you guys with such a simple question, but I really wasn't able to find a solution on my own.

    best,
    kiriri
     
    Last edited: Jul 11, 2012
  2. jcsd
  3. Jul 11, 2012 #2
    A bouncing object in general takes the form of an inverse parabola, and that is what games use nowadays for the jumping animation. The speed of the person while travelling in the parabolic shape can be given by another parabola, because the person starts out travelling fast, reaches its slowest and stops for a moment when he/she reaches the vertex of the parabola in the air and then starts accelerating again. Given that we take the parabola to be quadratic, there will be no problems with positiveness of distance and speed.

    Of course, you will need to determine a realistic vertex for the parabola, for to determine a parabola 2 points are not enough (the starting point and the terminating point.) The further you want to jump, the less you will go into the air. You need to determine also a realistic range for the person to jump. When you do determine this radius, try to meet the condition I specified. I do have something in mind but there are a lot of other alternatives, and you can't know which is the most sensible without testing (which I can't).
     
  4. Jul 11, 2012 #3

    chiro

    User Avatar
    Science Advisor

    Hey kiriri and welcome to the forums.

    For this problem, you can use the equation s = at2 + ut + c, but in the direction of your velocity and acceleration vectors which will be parrallel to each other.

    The first thing is that c will be the position (which is a vector) that corresponds to the balls position before it takes off. The a will be an acceleration vector corresponding to the force on the object when in free-fall which is going to be 9.8m/s in the direction that you decide for gravity (so probably -z direction in most 3D worlds, but it depends on what you use).

    The u vector is your velocity vector that you have to figure it in terms of the angle, and also with regard to finding the actual point.

    So here is the basic idea, what you do is you solve what is known as a boundary problem. You have a point of intersection that you want to to hit at t = t'. Don't worry about what this is at the moment, but what you have is that at some point in the future the s' for a given t' is equal to the point in space that you want the ball to hit.

    So here is what you know: you know s' (future point of ball to hit), you know s0, a, and probably ||u|| (the length of the velocity vector but not its direction), and you want to find the direction of u.

    If you know the time you want it to hit (in terms of time after the player launches or the ball launches), then you plug in this t' into the equation to solve for the vector u by solving:

    ut' = s' - at'2 - c where c is the initial launch spot, t' is the time elapsed (in seconds) after hitting the object and u is what you need to figure out. This is just substituting in the vectors a, s', c and the scalar quantity t'.

    If you have information about the magnitude of the velocity, then you get the equations:

    u^t' = (at'2 - c)/||u|| where ||u|| is the magnitude of the velocity the moment the leap is made.

    Again though, you still have a free parameter corresponding to the time it takes to get to the point and you will have to figure this out, and it will depend on your game code. For example you can aim really high and reach the mark on the way down or you can reach the point on the way up, depending on the requirements.

    The thing that you will have to factor in is the geometry surrounding the spot you wish to get: for example if you have say a solid ring surrounding the object, then you won't be able to do a steep angle shot because it would collide with the ring.

    So the first thing you need to do is to do some raycasting from the point of interest between the angles corresponding to the ray from the point of interest to point of leap all the way to the maximum position at the peak of the jump corresponding to a 45 degree leap (which is a maximum).

    Once you do these casts you will narrow down the possible solutions to for the leap and then you can use any such solution to construct a tangent vector condition which when worked backwards will give you a way to find the initial u vector.

    I know this is probably not clear as it could be so please clarify anything that needs to be made clearer by myself.
     
  5. Jul 12, 2012 #4
    wow, I wouldn't have thought I'd find other game makers here :D
    I think I now see that time is an essential part and I think I've managed to create some very close approximations based on delta y and delta x compared to the x speed and max x speed. I can't finish it until I have the jump tangent implemented, but I think this just might be possible :)

    Thank you chiro for your elaborate explanation. However, I fear you were right, I really don't understand all of it, no matter how hard I try to :S .
    Basically I can't comprehend how you got from
    to
    ?
    How can s' be of no importance in the second formula? and why has ut' become ut'?
     
    Last edited: Jul 12, 2012
  6. Jul 12, 2012 #5

    chiro

    User Avatar
    Science Advisor

    Sorry kiriri there was a mistake. It should be

    s = 1/2at2 + ut + c
    s' = 1/2at'2 + ut' + c and in terms of having a magnitude of velocity:

    u^t = [s - 1/2at'2 - c]/||u|| where ||u|| is the magnitude, and u^ is a direction vector. Use those equations instead with the 1/2 (and with the s included) instead of the other ones. You can derive them from integrating constant acceleration up to displacement by using initial conditions for velocity and displacement.

    I'm happy to go through the details though: it's not as hard as it first seems in terms of this formula: the hard part is using the geometry of the world and your game variables to come up with the right possible ways of doing so. For example if something was in a tube, then the only way you can get it is to go completely horizontal parallel to the surface of the cylinder, but if the thing was in open space, then you could approach it from many points.

    If you think about specific questions that will help you implement this, I'll do the best I can to help you (and also FYI I used to do game design myself).
     
  7. Jul 12, 2012 #6

    morrobay

    User Avatar
    Gold Member

    Have you looked in a physics text at the chapter on projectile motion ?
     
  8. Jul 13, 2012 #7

    HallsofIvy

    User Avatar
    Staff Emeritus
    Science Advisor

    There is acceleration, of value -g, vertically so, taking y as the height, v as the initial speed, (x_0, y_0) as the initial point, and [itex]\theta[/itex] is the angle of elevation at which is is projected, you have
    [itex]y= (a/2)t^2+ vcos(\theta)t+ y_0[/itex]
    and
    [itex]x= vsin(\theta)+ x_0[/itex]

    Setting those equal to the (x, y) coordinates of the point you want to hit gives you two equations to solve for t and [itex]\theta[/b]. Notice that the equation for y is quadratic. There will, in general, be two different angles at which you could "fire" and hit the target. Of course, there might be no real solution- if you are trying to hit a target beyond your range.
     
  9. Jul 13, 2012 #8

    chiro

    User Avatar
    Science Advisor

    That is not the only problem though: as pointed out, certain geometry may in fact yield no solutions to the target even being hit, even if the quadratic does have one or more solutions.
     
  10. Jul 27, 2012 #9

    morrobay

    User Avatar
    Gold Member

    The delayed reply is from moving. Can you get at this angle with these equations
    from projectile motion :
    x/(t)(v0) = cos theta

    y + 1/2gt2 /(v0)(t) = sin theta

    From x = (vo cos theta)t
    y = ( v0 sin theta) t - 1/2gt2
    at any time t
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Calculate throw angle to have the curve cross a certain point
Loading...