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

1. Sep 8, 2010

### Arioch82

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:

$$p_0 = (x_0, y_0, z_0)$$ as my start (launch) point (input value)

$$p_t = (x_t, y_t, z_t)$$ as my target point (input value)

$$v_0$$ velocity (input value)

$$g = 9.81$$ gravity

$$\vec g_v = (0, g, 0)$$ gravity vector

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

I define:

$$x_p = dist_{xz}$$
$$y_p = y_t$$

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:

$$y_p = \frac{-g}{2{(v_0\cos\theta)}^2}x_p^2 + x_p\tan\theta + y_0$$

defining:

$$\alpha = \frac{-g}{2v_0^2}$$
$$\phi = \tan\theta$$

developing:

$$(\alpha x_p^2)\phi^2 + x_p\phi + (y_0 - y_p + \alpha x_p^2) = 0$$

from here:

$$a = \alpha x_p^2$$
$$b = x_p$$
$$c = y_0 - y_p + \alpha x_p^2$$

$$\theta = \arctan{ \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} }$$

from the launch angle $$\theta$$ I have that the velocity vector is

$$v.x = \frac{x_t-x_0}{dist_{xz}} \cos\theta$$

$$v.z = \frac{z_t-z_0}{dist_{xz}} \cos\theta$$

$$v.y = \sin\theta$$

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

$$projectile(t) = p_0 + \vec v t - \frac{1}{2} \vec g_v t^2$$

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 $$x_p, y_p$$ 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:

File size:
24.9 KB
Views:
138
• ###### parabola2.jpg
File size:
25.2 KB
Views:
136
Last edited: Sep 9, 2010
2. Sep 9, 2010

### Petr Mugver

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

$$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]$$

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

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

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
3. Sep 9, 2010

### Arioch82

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)

File size:
20 KB
Views:
112
4. Sep 9, 2010

### betel

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.

5. Sep 9, 2010

### Arioch82

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 $$t$$, maybe I should act on the formula before it?

6. Sep 9, 2010

### mugaliens

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
7. Sep 9, 2010

### betel

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
$$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}$$

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

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
8. Sep 9, 2010

### Arioch82

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

9. Sep 9, 2010

### Arioch82

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

10. Sep 9, 2010

### betel

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.

11. Sep 9, 2010

### betel

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.

12. Sep 9, 2010

### Arioch82

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

13. Sep 9, 2010

### betel

Then the matrix above will work. If your start point is not the origin you have to shift everything before applying the matrix.
$$\vec v' = R(\theta)(\vec v - \vec v_0)+\vec v_0$$ and $$\vec v_0$$ are the coordinates of your start point.

14. Sep 9, 2010

### Arioch82

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 $$projectile(t)$$ 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:

• ###### parabola4.jpg
File size:
18.4 KB
Views:
101
Last edited: Sep 9, 2010
15. Sep 9, 2010

### betel

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 $$\Delta x,\Delta z$$?

Your original trajectory will be something like
$$\vec v(t)=\begin{pmatrix} x(t)\\0\\z(t)\end{pmatrix}$$
You get your new trajectory if you apply the Rotationmatrix to this vector.

16. Sep 9, 2010

### Arioch82

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)

17. Sep 9, 2010

### betel

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

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
18. Sep 9, 2010

### betel

Ok, i just noticed a typo in my matrix. the 3,1 component has to be changed to contain $$\cos\theta$$ instead of sin. The correct matrix is $$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}$$

19. Sep 9, 2010

### Arioch82

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 $$projectile(t)$$.

I've also noticed that you apply it to

$$\vec v(t)=\begin{pmatrix} x(t)\\0\\z(t)\end{pmatrix}$$

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

$$\begin{pmatrix} \Delta x\\0\\\Delta z\end{pmatrix}$$

did you mean $$\vec v(t)$$ translated to the origin with these $$\Delta$$ or do you actually mean the axis vector used in the matrix?

20. Sep 9, 2010

### betel

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 $$\Delta x$$ to indicate the difference between start and target. Written in the vector this means the axis vector.