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

3d parabola (projectile motion) to hit a target on an arbitrary plane

  1. Sep 8, 2010 #1
    Hi everyone,

    I'm a software engineer (sorry in advance if I made/will make some math mistake) and I'm trying to calculate the projectile motion from one point to hit a specific target in a 3d space so that the parabola will lie on an arbitrary plane.

    Is several days that I'm trying to achieve this without any luck, I'll be glad for any help... i should really finish this work at the most in a couple of days...

    Currently I've got my parabola working without rotations on the Z/X axis so I can hit any target with a parabola lying on a plane perpendicular to XZ (see attachment, the green line is the velocity vector).

    What I would love to do is calculate the other parabolas that can hit my target (lying on some other planes) if possible specifying a rotation angle (around the axis that goes through start and end point maybe?)

    Hope my problem is clear enough...

    Anyway that's what I'm currently using.

    having:

    [tex]p_0 = (x_0, y_0, z_0) [/tex] as my start (launch) point (input value)

    [tex]p_t = (x_t, y_t, z_t)[/tex] as my target point (input value)

    [tex]v_0[/tex] velocity (input value)

    [tex]g = 9.81[/tex] gravity

    [tex]\vec g_v = (0, g, 0)[/tex] gravity vector

    [tex]dist_{xz} = \sqrt{(x_t - x_s)^2 + (z_t - z_s)^2}[/tex] distance on the XZ plane

    I define:

    [tex]x_p = dist_{xz}[/tex]
    [tex]y_p = y_t[/tex]

    as my "target coordinate on the parabola plane" (sorry don't know how to define it in proper english, hope it will be clear enough looking at the next formula) for the parabola lying on the plane perpendicular to XZ (so gravity on the Y plane)

    From here I can calculate the angle to hit my target on that plane starting from:

    [tex]y_p = \frac{-g}{2{(v_0\cos\theta)}^2}x_p^2 + x_p\tan\theta + y_0[/tex]

    defining:

    [tex]\alpha = \frac{-g}{2v_0^2}[/tex]
    [tex]\phi = \tan\theta[/tex]

    developing:

    [tex](\alpha x_p^2)\phi^2 + x_p\phi + (y_0 - y_p + \alpha x_p^2) = 0[/tex]

    from here:

    [tex]a = \alpha x_p^2[/tex]
    [tex]b = x_p[/tex]
    [tex]c = y_0 - y_p + \alpha x_p^2[/tex]

    [tex]\theta = \arctan{ \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} }[/tex]

    from the launch angle [tex]\theta[/tex] I have that the velocity vector is

    [tex]v.x = \frac{x_t-x_0}{dist_{xz}} \cos\theta[/tex]

    [tex]v.z = \frac{z_t-z_0}{dist_{xz}} \cos\theta[/tex]

    [tex]v.y = \sin\theta[/tex]

    that I can scale as I like and use hit like:

    [tex]projectile(t) = p_0 + \vec v t - \frac{1}{2} \vec g_v t^2[/tex]

    to get my motion and hit the target.

    Now as I said this works just fine, I've my projectile hitting the target without any problem.
    I think I should act on [tex]x_p, y_p[/tex] and on the gravity vector but I cannot get it to work...

    Thank you in advance.

    edit:
    if it's not clear enough please let me know and I'll try to explain myself in a better way, unfortunatly as you could've noticed my mothertongue is not english...

    edit2:
    modified the first screenshot and added a new one to show the goal the I would like to reach (i got something close to it cheating on the math...)
     

    Attached Files:

    Last edited: Sep 9, 2010
  2. jcsd
  3. Sep 9, 2010 #2
    I don't understand your question too much, but I understand it has to do with rotations...
    A rotation is a 3x3 matrix. You can obtain it this way. Define the 4 matrices

    [tex]I=\left[\begin{array}{ccc}1&0&0\\0&1&0\\0&0&1\end{array}\right]\qquad
    A_1=\left[\begin{array}{ccc}0&0&0\\0&0&1\\0&-1&0\end{array}\right]\qquad A_2=\left[\begin{array}{ccc}0&0&-1\\0&0&0\\1&0&0\end{array}\right]\qquad A_3=\left[\begin{array}{ccc}0&1&0\\-1&0&0\\0&0&0\end{array}\right][/tex]

    If [tex]\theta[/tex] is the angle of rotation (anticlockwise) and [tex](n_1,n_2,n_3)[/tex] is the axis of rotation (such that [tex]|\mathbf{n}|^2=n_1^2+n_2^2+n_3^2=1[/tex]) then your rotation is

    [tex]R=\cos\theta I+(1-\cos\theta)\mathbf{n}^T\cdot\mathbf{n}+\sin\theta(n_1A_1+n_2A_2+n_3A_3)[/tex]

    where the dot is the usual row-colums multiplication of matrices. If you apply R to anything, you'll get that thing rotated in the desired way!
     
    Last edited: Sep 9, 2010
  4. Sep 9, 2010 #3
    Hi Petr and thank you for your reply.

    unfortunatly I've already tried that one and it doesn't give me the desired result.

    If you see the new screenshot attached to this post you can notice that in that way (well I'm using quaternions instead of a matrix but it should be the same) the all parabola rotates around the axis while a need the start (point with the axis displayed) and the goal (green sphere at the end of the cyan line) to be fixed so that i can launch my projectile from my start point to hit a specific target as like an "effect/curl" is applied to the parabola.

    in the screenshot I'm applying a rotation around the cyan axis, I've also tried around the magenta one (direction on the XZ plane) with similar result.
    The first red segment from the start point to the start of the parabola is displayed only because I'm assuming that the start point is always the first point (t=0)
     

    Attached Files:

  5. Sep 9, 2010 #4
    I dont' understand what you want to rotate.

    With the coordinates of cannon and target, gravitiy and initial velocity fixed there are only two trajectories your projectile can take to hit the target. Both lie in the same plane.

    If you want to achieve a trajectory similiar to the parabola in your second screenshot, without using rotating projecting of some other external force like wind, etc. this is impossible.
     
  6. Sep 9, 2010 #5
    Yes i would like to achieve a trajectory like the second screenshot.
    It's ok to use rotation/projection but when I try to use them my result is like the third screenshot so that it doesn't start on my start point and it doesn't hit the target (like the second screenshot)

    I think is because I'm applying the rotation after calculating the point at the time [tex]t[/tex], maybe I should act on the formula before it?
     
  7. Sep 9, 2010 #6
    A parabolic orbit isa Kepler orbit with an eccentricity equal to 1. In short, it's the very rare case which is both an escape or capture orbit.

    Orbits with less than escape velocity follow an http://en.wikipedia.org/wiki/Elliptic_orbit" [Broken]...
     
    Last edited by a moderator: May 4, 2017
  8. Sep 9, 2010 #7
    Whatever force you use I'm pretty sure it will not be a parabola any more, but if you want to rotate your original parabola, Petr matrices are the way to go. Explicitly you have to multiply your coordinates by the following matrix
    [tex] R(\theta)=\begin{pmatrix} \Delta z^2\cos \theta + \Delta x^2 & -\Delta z\sin\thet& \Delta x\Delta z(1-\cos\theta)\\ \Delta z\sin\theta& \cos\theta&-\Delta x \sin\theta\\ \Delta x\Delta z (1-\sin\theta)&\Delta x \sin \theta& \Delta x^2\cos\theta + \Delta z^2\end{pmatrix}[/tex]

    where [tex]\Delta x,\Delta z[/tex] is the difference in your coordinates normalized to 1, i.e. [tex] \Delta x^2+\Delta z^2=1[/tex]

    But to really get a correct trajectory you would first have to specify the mechanism how the make your projectile go back towards the target again.
     
    Last edited: Sep 9, 2010
  9. Sep 9, 2010 #8
    thx for the link I'll try to understand as much as i can... as I said I'm not a physicist or a mathematician and all these names/equations are just scaring me :)

    I'll be back to you after reading all those links.
    Cheers
     
  10. Sep 9, 2010 #9
    hi betel,

    thanks for the matrix as I said I've already tried it with quaternions, rotation around the cyan axis in the screenshot (but as you can see it didn't work), I'll give the matrix a try.

    What do you mean with "specify the machanism..."?
    Because I think that's my main problem (also with the quaternion approach)...
     
  11. Sep 9, 2010 #10
    If you only have gravity acting your cannot shoot your projectile sideways and have it come back to the target.
    If you know what is driving the projectile back you can calculate the trajectory. But in general this trajectory will not be a rotated parabola.
     
  12. Sep 9, 2010 #11
    Watch out.
    1. I corrected some typos.
    2. For the matrix to work the line conneting target and start has to go through the origin. Anyway the calculations will be much easier if you choose the start point to be the origin.
     
  13. Sep 9, 2010 #12
    ok, I think that's fundamental, that's why I was thinking about rotating the gravity vector too so that it always lie on the parabola plane.

    Otherwise I do not have any wind or external force but I have no problem to add one.

    I don't care if is not exactly a parabola, so now the question is:

    how can i calculate the trajectory in that case so to hit my target?

    Thanks again
     
  14. Sep 9, 2010 #13
    Then the matrix above will work. If your start point is not the origin you have to shift everything before applying the matrix.
    [tex]\vec v' = R(\theta)(\vec v - \vec v_0)+\vec v_0[/tex] and [tex] \vec v_0[/tex] are the coordinates of your start point.
     
  15. Sep 9, 2010 #14
    ok, I've applied that matrix, is going better as the parabola now starts on my start point but it's still not hitting the target... (see screenshot)

    I think now is matter of "recalcute the trajectory" that you were speaking about?
    I'm applying the matrix on every [tex]projectile(t)[/tex] not on the formula before to find the angle/velocity_vector to hit the target (or the gravity, or anything else), is it correct, isn't it?

    thanks again for your help

    edit:
    maybe is because:
    in my case is not true?

    I'm applying the matrix translating the point to the origin first and then translating it back as you also wrote in your last post
     

    Attached Files:

    Last edited: Sep 9, 2010
  16. Sep 9, 2010 #15
    I checked it by hand and the parabola should start and end at the correct points
    Did you choose (0,0,0) as coordinates for your start point?
    Did you use the uptodate version of the matrix? Did you normalize [tex]\Delta x,\Delta z[/tex]?

    Your original trajectory will be something like
    [tex]\vec v(t)=\begin{pmatrix} x(t)\\0\\z(t)\end{pmatrix}[/tex]
    You get your new trajectory if you apply the Rotationmatrix to this vector.
     
  17. Sep 9, 2010 #16
    yes the formulas in my code are exactly the same you wrote here.

    the start point doesn't need to be on the origin.
    I found out that it works correctly only if the Y for start point and end point are the same and also one of X or Z is the same too (so like X and Y are the same or Z and Y are the same, if it's only Y it won't work)

    in the previous screenshot as you can see it's an uphill shoot (the magenta line is the distance on the XZ plane while the cyan one is the axis connecting start and end point)

    maybe it depends on the way i calculate the angle/velocity vector? (see first post)
     
  18. Sep 9, 2010 #17
    Any point on the line between the start and the target should be left untouched by the rotation, so the parabolar should always go through the target point.
    [tex] R(\theta)=\begin{pmatrix} \Delta z^2\cos \theta + \Delta x^2 & -\Delta z\sin\thet& \Delta x\Delta z(1-\cos\theta)\\ \Delta z\sin\theta& \cos\theta&-\Delta x \sin\theta\\ \Delta x\Delta z (1-\cos\theta)&\Delta x \sin \theta& \Delta x^2\cos\theta + \Delta z^2\end{pmatrix}
    \begin{pmatrix} \Delta x\\0\\\Delta z\end{pmatrix}=
    \begin{pmatrix}
    \Delta x^3 + \Delta z^2\Delta x\cos\theta+\Delta x\Delta z^2(1-\cos\theta)\\
    0\\
    \Delta z^3 + \Delta x^2 \Delta z\cos\theta+\Delta x^2\Delta z(1-\cos\theta)
    \end{pmatrix}=
    \begin{pmatrix}
    \Delta x(\Delta x^2+\Delta z^2)\\
    0\\
    \Delta z(\Delta x^2+\Delta z^2)\\
    \end{pmatrix}=
    \begin{pmatrix}
    \Delta x\\
    0\\
    \Delta z\\
    \end{pmatrix}[/tex]

    So if your parabola is not hitting the target something is wrong with either the rotation or the parabola. Can you please post the formula for the trajectory of you r projectile? Then we can check if there is something wrong in there.
     
    Last edited: Sep 9, 2010
  19. Sep 9, 2010 #18
    Ok, i just noticed a typo in my matrix. the 3,1 component has to be changed to contain [tex]\cos\theta[/tex] instead of sin. The correct matrix is [tex]
    R(\theta)=\begin{pmatrix} \Delta z^2\cos \theta + \Delta x^2 & -\Delta z\sin\thet& \Delta x\Delta z(1-\cos\theta)\\ \Delta z\sin\theta& \cos\theta&-\Delta x \sin\theta\\ \Delta x\Delta z (1-\cos\theta)&\Delta x \sin \theta& \Delta x^2\cos\theta + \Delta z^2\end{pmatrix}
    \begin{pmatrix} \Delta x\\0\\\Delta z\end{pmatrix}[/tex]
     
  20. Sep 9, 2010 #19
    great now it works with any X and Z but the Y coordinate always needs to be the same between start and target point otherwise it won't hit the target.

    what do you mean with

    my trajectory formula is on the first post.
    what I'm doing is applying that matrix to [tex]projectile(t)[/tex].

    I've also noticed that you apply it to

    [tex]\vec v(t)=\begin{pmatrix} x(t)\\0\\z(t)\end{pmatrix}[/tex]

    with Y=0, any reason for that? (my start and target can be at any Y and the shoot can be uphill, downhill, straight...)

    and I don't understand in the last couple of post why you're multiplying the matrix with

    [tex]\begin{pmatrix} \Delta x\\0\\\Delta z\end{pmatrix}[/tex]

    did you mean [tex]\vec v(t)[/tex] translated to the origin with these [tex]\Delta[/tex] or do you actually mean the axis vector used in the matrix?
     
  21. Sep 9, 2010 #20
    Your projectile(t) is a scalar. I don't know how you apply the matrix to it.

    The formula works only for y=0, because you stated that start and target lie in the xz plane. So the differenc in the y direction is 0. For any y you can either change your coordinates or calculate the general matrix from Petr's formula.

    I write [tex]\Delta x[/tex] to indicate the difference between start and target. Written in the vector this means the axis vector.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: 3d parabola (projectile motion) to hit a target on an arbitrary plane
Loading...