Jump to content

Velocity of object moving on parabole

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
11 replies to this topic

#1
Maurice_Z

Maurice_Z

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
Not really sure how to describe my problem so I wil ljust dive into the details.

I have a parabole:
Posted Image

Now, from point A i want to shoot an object which would follow the parabole's path. The object moves with constant horizontal speed and a constant vertical gravity is applied to it per step (in the usual game environment, no fancy physics). In other words, the object has four properties (x, y, horizontalSpeed and verticalSpeed) and every step its action looks like this:
x += horizontalSpeed;

y += verticalSpeed;


verticalSpeed += gravity; //In my case gravity is equal to 0.2

and the variables are set to:
x = A.x;

y = A.y;

horizontalSpeed = cos(angle)*speed;

verticalSpeed = sin(angle)*speed;

I can get the angle of movement but no luck finding the speed/velocity, and I am fairly sure there has to be some formula to do get it. The "data" I have is:
A point's X and Y,
Parabola's vertice's X and Y,
a, b and c (from ax^2 + bx +c) of the parabola

I think that would be all. Thanks in advance! I will try to get the solution (again) by myself now :).

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
speed = sqrt((horizontalSpeed)^2 + (verticalSpeed)^2)
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Maurice_Z

Maurice_Z

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts

WingedPanther said:

speed = sqrt((horizontalSpeed)^2 + (verticalSpeed)^2)

The thing is that I know neither the horizontal nor the vertical speed - they are what I am trying to find.

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
So your goal is to get the initial velocity necessary to create a specific parabola? Are you familiar with calculus at all?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
Maurice_Z

Maurice_Z

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts

WingedPanther said:

So your goal is to get the initial velocity necessary to create a specific parabola? Are you familiar with calculus at all?

Yes, pretty much that's what I am trying to achieve. I am familiar, at least a bit.

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Given Ax^2 + Bx + C, you have 2Ax + B is the vertical velocity as a function of x, and 2A = gravity.

So, you multiply 2A by a constant to determine the multiplier, and that gives you your multiplier to get horizontal/vertical speed, and you solve for your initial point to get the x value when launched (using quadratic formula).
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#7
Maurice_Z

Maurice_Z

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
I think you lost me somewhere and I am not even entirely sure where (It's difficult to understand mathematics in English when you are learning them in Polish). I understand how derivatives work but that does not help really much.

I tried implementing what you just wrote the way I understood and the result I got is:
speed = 2*a*x + b; //And some other, similar;
But that's unfortunately not working and I scan what you wrote again and again and I can't seem to apply my knowledge to what you said.

Could you please somehow rephrase what you wrote?

#8
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Let's stop for a second and regroup.
You posted a LOT of material, and I suspect some of it is irrelevant to the problem.

You are given the following:
A point's X and Y, - the "fire" point
Parabola's vertice's X and Y, - the point where the vertical velocity = 0
a, b and c (from ax^2 + bx +c) of the parabola - is this actually given, or what you want to find?

If you are actually given a,b,c, then all you need to do is draw the parabola VERY slowly. If you need to solve for a, b, and c, then we have a slightly tougher problem.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#9
Maurice_Z

Maurice_Z

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
No, unfortunately, whilst I thought about it it's not really feasible, because I want to be able to move that object later (eg. It is an enemy's trajectory and I want to be able to shoot him and the shoot should modify his movement pattern; or it is a ball which I want then to bounce).

#10
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
That sounds like a situation where you need the initial vector and position. When there's a collision, recalculate the vector and start over.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#11
Maurice_Z

Maurice_Z

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
Yes, that's basically what I need (I guess I could have overcomplicated it). While I know the initial position (the point A) I can't get the speed/movement vector. I've been trying to do some math, but all the things I come up with end as failure.

Edit:
Thank goodness and other great things! Finally, after scribbling over 6 pages of formulas I have managed to get the solution! In case anyone stumbles upon a need for one too, below I present the way I found it. Please note that this is 'hackish' solution and it is made for Actionscript 3.0:


So first we have a couple of variables for later use:
startX, startY - the starting X and Y positions;
A, B, C - the quadratic equation's values (AX^2 + BX + C);
gravity - in pixels per step;
topX, topY - will come in handy in AS3;

First of all we have to compute the angle. We use the derivative of the quadratic equation, that is:
angle = Math.atan(2*a*startX+b);
And a little hack so the angle has full range:
if (topX - startX<0){ angle -=Math.PI; }
Generally, we want to find such X speed (vX) so that whenever we move by it, the Y speed willdecrease by gravity. In other words, speed difference between two steps has to be gravity. We calculate the speed by using formula (f=quadratic formula):
v1 = f(x) - f(x+vX);
v2 = f(x+vX) - f(x+2*xV);

And the difference is:
v1-v2 = f(x) - 2*f(x+vX) + f(x+2*vX);
Which after some trasnformations and calculations gives:
vX = Math.sqrt(gravity / (2*a));
Using simple trigonometry we get the Y speed:
vY = Math.tan(angle) * vX;

And that's it.

Edited by Maurice_Z, 09 February 2010 - 03:36 AM.
Found solution


#12
hetra

hetra

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 298 posts
Well is this on Earth or some other gravitating body?

I would consider the general curvature of the fabric of spacetime, but that's just me.

For programming sake what language are you using?

As a 7grade-8 grade student I like studying these things.