Jump to content

  • Log In with Google      Sign In   
  • Create Account


2D Parabolic Arc between dynamic A-B


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 ElganSayer   Members   -  Reputation: 101

Like
0Likes
Like

Posted 20 October 2012 - 10:21 AM

Hello,
I have a problem and I'm not smart enough to work out a solutions.

I want to achieve a throw, a bomb between two points, and so it travels as an arc from point A, to point B. Point B is known and the bomb must land on point B


if the distance between the two positions AB is dynamic and the horizontal distance changes, the vertical distance may also change.


How can we know the initial vertical velocity in which to throw the object to make it art exactly on to position B?

How can I calculate it so my bomb moves in an arc from whatever point A is, so that it hits point B in an ARC. I have no idea, using other istes this is what I tried, i tried at least...then realized I have no idea for how long to run the loop for, and have no idea how to hit point b exactly.

tagetTilePosition is a vector ( 0 , 0 )
double startX = bombPosition.x;   // initial position
double startY =  bombPosition.y;   //   of the object
float angle = 45.0f * Mathf.Deg2Rad;
const double g = 9.8;	   // gravity (meters/s^2)
double velocity =20.0;
double Vx = velocity * Mathf.Cos(angle);  // x (horizontal) component of velocity
double Vy = velocity * Mathf.Sin(angle);  // y (vertical)   component of velocity
 
Vector2 distance = ( bombPosition2 - tagetTilePosition );
 
  //guessing
  double endTime = ( distance.x + distance.y ) / velocity ;
 
  for(double wait = 1; wait <= endTime ; wait += 1f)
  {
  /*
   float v_v;
   double g = 9.8f
   float s;
   float t = wait;
  
   s = bombPosition.y;
   t = d / v_h
   v_v = (0.5f * g * (t * t) + s) / t;
   */
   double  t = wait;
   double x = startX + Vx * t;
   double y = startY + Vy * t - 0.5 * g * t * t;
   bombPosition.x = (float) x;
   bombPosition.y = (float) y;
  
  // bombPosition.x = centre.x += ( 60 * Mathf.Cos ( (float) wait )  );
   //bombPosition.y = centre.y -=  ( 60 * Mathf.Sin ( (float) wait)  );
  
   bomb.transform.position = bombPosition;
  }


Sponsor:

#2 Bacterius   Crossbones+   -  Reputation: 8178

Like
2Likes
Like

Posted 20 October 2012 - 10:25 PM

Assuming gravity is the only force on the bomb, and is strictly downwards, and that point does not move while the bomb is in the air (obviously) and that there are no obstacles to consider, then you can in fact work out the exact initial velocity vector needed to hit point . First, let be at coordinates and at coordinates .

Then, using some kinematics, the position of the bomb at any time will be:



So for the bomb to hit somehow, we need the coordinates of the bomb to satisfy:




For some . Rearranging:





Simplifying:




This is a parametric equation in , which basically gives a bigger and bigger velocity vector as you decrease the time (the faster you shoot, the less time gravity has to effect the bomb, so at infinite speed you can pretty much just aim towards B and shoot). As you increase the time , gravity becomes more important (see the gravity term in the equation) and the direction itself matters less, so you get an increasingly large arc. Here's a rough plot of the parametric I made with a throwaway program:

Posted Image

If you need the bomb to stay a certain amount of time in the air, just plug the correct in, and you have your velocity vector! If you need your velocity vector to be a certain length (for instance, the amount of force with which the bomb is launched), you can use that information to deduce as well. You could also calculate the energy requirements for a given and compare them with whatever energy your bomb cannon has to select the correct one, if you wanted to get really fancy.

N.B. This can be generalized to any gravity vector and to higher dimensions by modifying the kinematics accordingly, but for the sake of simplicity and without loss of generality, only gravity in the vertical direction for the two-dimensional case is considered.

Edited by Bacterius, 20 October 2012 - 10:34 PM.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#3 Bacterius   Crossbones+   -  Reputation: 8178

Like
2Likes
Like

Posted 04 November 2012 - 09:22 PM

For completeness, I provide the fully generalized version in this post (since I guess someone will eventually ask). Let be the initial position vector and the final position vector . We want to find an initial velocity vector such that a projectile fired from with this velocity vector will collide with when subject to some constant force producing an acceleration on it. Note if the projectile has mass , then as expected.

Let be the position of the projectile at time after launch. Then from kinematics, for we have:



And for the projectile to collide with , its position must satisfy for some time , so:







Yielding a family of solutions for for any positive . Negative works too, but it makes little sense since the intersection would have occurred before the projectile was launched, extrapolating its trajectory into the past - though you will notice flipping the sign of flips the sign of and thus simply inverts the direction of anyway. This is a very nice and flexible result.

--------------------------------

What about nonconstant forces? Suppose varies with time, so . The force/mass relationship still works, of course. Perhaps this could take into account gravity as well as wind (possibly via some sinusoidal function to simulate atmospheric fluctuations). Can we still predict the correct velocity vector? The answer is, surprisingly, yes, but we must use calculus. We must integrate this acceleration function with respect to time once to obtain velocity, and once again to obtain displacement, which results in the following trajectory for :



With the same criterion as before, this gives:



And rearranging as we did before:



Which, interestingly enough, is a parametric solution in . Now, actually evaluating the double integral is probably the hardest part, especially if you're using some complex function such as perlin noise as the acceleration, but if worst comes to worst, approximations exist. Besides, it's likely your predicted trajectory doesn't have to be perfect, but just close enough.

Let's try and pick some relatively simple time-varying function and see if it works. For instance, let's say in our hypothetical world, gravity is modulated by a sinusoidal function. Kind of weird, but hey. So for instance, we have . Then the double integral is easy enough to calculate (remember those are definite integrals):



So let's plug everything into our parametric equation and see what we get:



The resulting trajectory for some is illustrated below:
Posted Image

What about a different time-varying function, let's say . Then the double integral is more complicated but still tractable:



Which gives the following trajectory for some (this is not a parabola):
Posted Image

--------------------------------

Note if , then the double integral becomes , and we get back the familiar kinematics equation. If then you just get back as you would expect. It's also possible to make the force vary on position instead of just time, but you need more integrals and it just gets messy and tedious to calculate, so we'll leave it at that.

--------------------------------

Additional note: if happens to be moving, you can also take that into account (isn't math wonderful) by changing the term - which is a position - into a function of time . If you want a time-varying force to be applied to , you can use the same methods as above, which involve another double integral. However at this point, the problem essentially boils down to finding a parameterized intersection of two differential curves, which might be better tackled by other methods involving more specialized forms of calculus.

Edited by Bacterius, 05 November 2012 - 12:22 PM.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS