Recent

Author Topic: Projectile motion  (Read 6948 times)

zivezive112

  • Newbie
  • Posts: 1
Projectile motion
« on: June 13, 2017, 12:24:53 am »
I have to make a graph of projectile motion where I can choose the angle, and make it draw a graph on the button click. Any ideas how i could do that?

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Projectile motion
« Reply #1 on: June 13, 2017, 01:17:51 am »
.
I have to make a graph of projectile motion where I can choose the angle, and make it draw a graph on the button click. Any ideas how i could do that?

a projectile motion can be descripted perfectly with a quadratic bezier curve. a quadratic bezier curve is a curve defined by 4 points in a plane, the start point then end point and two weight points in between them. you can use the first weight point, which is linked usually to the start point, to emulate acceleration and angle of fire. The second weight point is used to emulate gravity. That's the general idea of the emulation if anything is not clear do ask. If you haven't learn bezier curves yet please inform us what you have learn for ballistics calculations so far
« Last Edit: June 13, 2017, 10:11:45 am by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Handoko

  • Hero Member
  • *****
  • Posts: 5507
  • My goal: build my own game engine using Lazarus
Re: Projectile motion
« Reply #2 on: June 13, 2017, 04:29:34 am »
@zivezive112
Which one did you mean, how to use the graphics library or the calculation?

If you want to know the calculation, here:
https://en.wikipedia.org/wiki/Projectile_motion

Edson

  • Hero Member
  • *****
  • Posts: 1325
Re: Projectile motion
« Reply #3 on: June 13, 2017, 04:53:41 am »
The math calculation is simple. You can consider the two components of the movement.
The horizontal position, increases at a constant speed:

  x := v * t.

The vertical position increases and decreases according a quadratic equation:

  y := 0.5 * g * t^2

Where g is constant and is th gravity.  You must start from a negative x, is the projectile is launched to up.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

Eugene Loza

  • Hero Member
  • *****
  • Posts: 729
    • My games in Pascal
Re: Projectile motion
« Reply #4 on: June 13, 2017, 08:21:32 am »
I have to make a graph of projectile motion where I can choose the angle, and make it draw a graph on the button click. Any ideas how i could do that?
And from the practical sense: add an image and a button to your form. Add a click event for button and in the event (which is just a procedure) write an output to image1.canvast according to the abovegiven formulae. You may just do it by moveto---lineto.
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

wp

  • Hero Member
  • *****
  • Posts: 13268
Re: Projectile motion
« Reply #5 on: June 13, 2017, 09:08:25 am »
Edson, your formulas are correct only for throwing horizontally. But the OP needs also a dependence on the throw angle. The link given by Handoko contains all.

With all the formulas known, the graph can be drawn most easily by TAChart (http://wiki.lazarus.freepascal.org/TAChart_Tutorial:_Function_Series).

balazsszekely

  • Guest
Re: Projectile motion
« Reply #6 on: June 13, 2017, 09:52:16 am »
See attachment.

PS: If you want to take into account the air resistance the whole calculation must be redone. The air resistance is proportional with the velocity(at low speeds) so you gonna get a nice differential equation(nice-->separable). 

PS1: Source code removed for now. See @wp, @rvk post below. For those who are still interested(at least with 100+ post) pm for the source.
« Last Edit: June 13, 2017, 10:26:48 am by GetMem »

wp

  • Hero Member
  • *****
  • Posts: 13268
Re: Projectile motion
« Reply #7 on: June 13, 2017, 09:57:06 am »
GetMem, sorry, but I think it is not a good idea to post the full code here because this looks like some homework assignment.

rvk

  • Hero Member
  • *****
  • Posts: 6910
Re: Projectile motion
« Reply #8 on: June 13, 2017, 10:07:09 am »
And we all know what happens with the last homework assignment from yesterday. OP just changed the openingspost to 123 after getting the answer.

(And it just so happens that zivezive112 (op) signed on after killabeez62 removed his/her account.)

I think posts shouldn't be allowed to be changed (maybe after an hour or so). At least not by newcomers.

balazsszekely

  • Guest
Re: Projectile motion
« Reply #9 on: June 13, 2017, 10:09:36 am »
Quote
@wp
Sorry, but I think it is not a good idea to post the full code here because this looks like some homework assignment.
Yes, you're probably right. I just noticed that @zivezive112 never posted before.

Quote
@rvk
And we all know what happens with the last homework assignment from yesterday. OP just changed the openingspost to 123 after getting the answer.
(And it just so happens that zivezive112 (op) signed on after killabeez62 removed his/her account.)
I think posts shouldn't be allowed to be changed (maybe after an hour or so). At least not by newcomers.
I wasn't aware what happened yesterday.

Attachment removed.

Edson

  • Hero Member
  • *****
  • Posts: 1325
Re: Projectile motion
« Reply #10 on: June 13, 2017, 05:15:26 pm »
Edson, your formulas are correct only for throwing horizontally. But the OP needs also a dependence on the throw angle. The link given by Handoko contains all.

Not. They are all valid. Just have to separate the vertical and horizontal component of the initial speed. It is just basic geometry:

Vx = V * cos(alpha)
Vy = V * sin(alpha)

Then you can estimate, the initial "t" for the formula:   y := 0.5 * g * t^2
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

wp

  • Hero Member
  • *****
  • Posts: 13268
Re: Projectile motion
« Reply #11 on: June 13, 2017, 05:57:19 pm »
If t is time and x = v t and y = 0.5 g t^2 (pointing downward) then x and y only can increase with increasing time. There is no vx and no vy here. If an angle is introduced and vx and vy come into play then the formulas must be rewritten to x = vx t and y = vy t + 0.5 g t^2. Now x still increases linearly in time, but if vy is negative  (upward throw) then y first decreases (becomes negative) and then decreases. Note y is pointing downward in these formulas (which is very confusing - it would have been clearer to add a minus sign to the y formula to have y point upward)

Edson

  • Hero Member
  • *****
  • Posts: 1325
Re: Projectile motion
« Reply #12 on: June 13, 2017, 06:21:59 pm »
If t is time and x = v t and y = 0.5 g t^2 (pointing downward) then x and y only can increase with increasing time. There is no vx and no vy here. If an angle is introduced and vx and vy come into play then the formulas must be rewritten to x = vx t and y = vy t + 0.5 g t^2. Now x still increases linearly in time, but if vy is negative  (upward throw) then y first decreases (becomes negative) and then decreases. Note y is pointing downward in these formulas (which is very confusing - it would have been clearer to add a minus sign to the y formula to have y point upward)

I don't give all the formulas needed nor all the changes needed, I don't do homework. (Other way, I would send the program).

If someone have the interest on learn, I'm sure he/her will find the correct answer.  :)
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

sam707

  • Guest
Re: Projectile motion
« Reply #13 on: June 13, 2017, 10:47:43 pm »
i'm just gonna put that here = not so simple BUT not so hard  ;D
http://www.webassign.net/question_assets/buelemphys1/chapter04/section04dash7.pdf

all you need is in the above link tho

AND def YES, this forum is not a place to tell other ppl to do your own schoolworks assignements for you! MAKE IT YOURSELF!
« Last Edit: June 13, 2017, 10:54:43 pm by sam707 »

 

TinyPortal © 2005-2018