## Computer Graphics

Moderators: Sephiroth
Number of posts: 2641

This Forum Only

Help wanted on projectile equation for using in c++ Posted by stanley18 on 19 Aug 2006 at 8:03 PM
Will anybody help me on doing or atleast giveme an equation of a projectile.
all i need to do is show the path of a projectile using graphics in turbo c++.
for this i need to have x and y values of the projectile... so i need an equation...
help wanted ...
i need to submit my project soon....

Re: Help wanted on projectile equation for using in c++ Posted by IDK on 20 Aug 2006 at 1:08 AM
: Will anybody help me on doing or atleast giveme an equation of a projectile.
: all i need to do is show the path of a projectile using graphics in turbo c++.
: for this i need to have x and y values of the projectile... so i need an equation...
: help wanted ...
: i need to submit my project soon....
:
:
:
This is how I would design the universe

```while universe still is{
for each object{
o.x += o.dx
o.y += o.dy
o.z += o.dz

o.dx += all forces that affect the x axis of this object
o.dy += the same with the y
o.dz += and z

draw(o) //ok, this wouldn't exist in the universe but it
//is required in computers
}
}
```

If you want motion, init dx,dy,dz to the value you want.
If you want gravity, add it in the forces section
You don't need all the dimensions, if you're just going to program
on the screen then just discard z

Happy coding wishes
the one and only
Niklas Ulvinge aka IDK

Re: Help wanted on projectile equation for using in c++ Posted by gautam on 20 Aug 2006 at 3:13 AM
This message was edited by gautam at 2006-8-20 3:15:24

Hi,

Use the simple physics equations of motion in 2D dimensions.

s = ut + 0.5at*t
v = u + at
v*v = u*u + 2as

For projectiles make sure you take time into consideration or else you won't get the right physics results. So every time step like every second or millesecond you will get the distance to move in the next frame. And if you take a = -g(i.e -9.8 or approx -10 if working with integers) then you get the falling down effect.

: : Will anybody help me on doing or atleast giveme an equation of a projectile.
: : all i need to do is show the path of a projectile using graphics in turbo c++.
: : for this i need to have x and y values of the projectile... so i need an equation...
: : help wanted ...
: : i need to submit my project soon....
: :
: :
: :
: This is how I would design the universe
:
:
```: while universe still is{
:     for each object{
:         o.x += o.dx
:         o.y += o.dy
:         o.z += o.dz
:
:         o.dx += all forces that affect the x axis of this object
:         o.dy += the same with the y
:         o.dz += and z
:
:         draw(o) //ok, this wouldn't exist in the universe but it
:                 //is required in computers
:     }
: }
: ```

:
: If you want motion, init dx,dy,dz to the value you want.
: If you want gravity, add it in the forces section
: You don't need all the dimensions, if you're just going to program
: on the screen then just discard z
:
: Happy coding wishes
: the one and only
: Niklas Ulvinge aka IDK
:
:

Re: Help wanted on projectile equation for using in c++ Posted by IDK on 20 Aug 2006 at 3:44 AM
: This message was edited by gautam at 2006-8-20 3:15:24

: Hi,
:
: Use the simple physics equations of motion in 2D dimensions.
:
: s = ut + 0.5at*t
: v = u + at
: v*v = u*u + 2as
:
: For projectiles make sure you take time into consideration or else you won't get the right physics results. So every time step like every second or millesecond you will get the distance to move in the next frame. And if you take a = -g(i.e -9.8 or approx -10 if working with integers) then you get the falling down effect.
:
:

Thanks, I didn't manage to get the time right before...
But one problem with it, since a proccessor doesn't work on time, it works on clocks, and the process shares clocks with other processes, it's impossible to determine a time step without wait...

What are v,a,t,s,u?
Are they velocity, acceleration, time and length respectivly?
And what is u then?

I find english math very confusing sometimes, becouse they have a lot of other names in my native language, swedish...
Re: Help wanted on projectile equation for using in c++ Posted by stanley18 on 20 Aug 2006 at 4:27 AM
: : This message was edited by gautam at 2006-8-20 3:15:24

: : Hi,
: :
: : Use the simple physics equations of motion in 2D dimensions.
: :
: : s = ut + 0.5at*t
: : v = u + at
: : v*v = u*u + 2as
: :
: : For projectiles make sure you take time into consideration or else you won't get the right physics results. So every time step like every second or millesecond you will get the distance to move in the next frame. And if you take a = -g(i.e -9.8 or approx -10 if working with integers) then you get the falling down effect.
: :
: :
:
: Thanks, I didn't manage to get the time right before...
: But one problem with it, since a proccessor doesn't work on time, it works on clocks, and the process shares clocks with other processes, it's impossible to determine a time step without wait...
:
: What are v,a,t,s,u?
: Are they velocity, acceleration, time and length respectivly?
: And what is u then?
:
: I find english math very confusing sometimes, becouse they have a lot of other names in my native language, swedish...
:

ok.. the help was nice but i still dont know how to put it into a c++ program .... pls help
i want to show the motion of a projectile using a
c++ program

Re: Help wanted on projectile equation for using in c++ Posted by IDK on 20 Aug 2006 at 4:47 AM
: : : This message was edited by gautam at 2006-8-20 3:15:24

: : : Hi,
: : :
: : : Use the simple physics equations of motion in 2D dimensions.
: : :
: : : s = ut + 0.5at*t
: : : v = u + at
: : : v*v = u*u + 2as
: : :
: : : For projectiles make sure you take time into consideration or else you won't get the right physics results. So every time step like every second or millesecond you will get the distance to move in the next frame. And if you take a = -g(i.e -9.8 or approx -10 if working with integers) then you get the falling down effect.
: : :
: : :
: :
: : Thanks, I didn't manage to get the time right before...
: : But one problem with it, since a proccessor doesn't work on time, it works on clocks, and the process shares clocks with other processes, it's impossible to determine a time step without wait...
: :
: : What are v,a,t,s,u?
: : Are they velocity, acceleration, time and length respectivly?
: : And what is u then?
: :
: : I find english math very confusing sometimes, becouse they have a lot of other names in my native language, swedish...
: :
:
:
: ok.. the help was nice but i still dont know how to put it into a c++ program .... pls help
: i want to show the motion of a projectile using a
: c++ program
:
:

Use my code, apply guatams forces, write your drawing routine and voila, your done.
Re: Help wanted on projectile equation for using in c++ Posted by stanley18 on 20 Aug 2006 at 11:01 AM
: : : : This message was edited by gautam at 2006-8-20 3:15:24

: : : : Hi,
: : : :
: : : : Use the simple physics equations of motion in 2D dimensions.
: : : :
: : : : s = ut + 0.5at*t
: : : : v = u + at
: : : : v*v = u*u + 2as
: : : :
: : : : For projectiles make sure you take time into consideration or else you won't get the right physics results. So every time step like every second or millesecond you will get the distance to move in the next frame. And if you take a = -g(i.e -9.8 or approx -10 if working with integers) then you get the falling down effect.
: : : :
: : : :
: : :
: : : Thanks, I didn't manage to get the time right before...
: : : But one problem with it, since a proccessor doesn't work on time, it works on clocks, and the process shares clocks with other processes, it's impossible to determine a time step without wait...
: : :
: : : What are v,a,t,s,u?
: : : Are they velocity, acceleration, time and length respectivly?
: : : And what is u then?
: : :
: : : I find english math very confusing sometimes, becouse they have a lot of other names in my native language, swedish...
: : :
: :
: :
: : ok.. the help was nice but i still dont know how to put it into a c++ program .... pls help
: : i want to show the motion of a projectile using a
: : c++ program
: :
: :
:
: Use my code, apply guatams forces, write your drawing routine and voila, your done.
:
thank you .. all
my projects complete ...

Re: Help wanted on projectile equation for using in c++ Posted by gautam on 20 Aug 2006 at 7:54 PM
Here goes the explanation then (my physics is a little rusty) -
s = distance travelled
u = initial velocity
v = final velocity
a = acceleration which is -g(if gravity comes into play)

Time is the delta time (many times it is 0.016 which is 1/60 because of the 60 frames per second). You can also calculate this and then make use of it.

So if I have s = ut + 0.5at*t when I start -> on x-axis u = 0, t = 0.016, a = v(from v = u + at and t = 1sec), thus s = ut + 0.5vt*t. On the y-axis you take gravity and hence a = -g into account. It goes something like this.

: : This message was edited by gautam at 2006-8-20 3:15:24

: : Hi,
: :
: : Use the simple physics equations of motion in 2D dimensions.
: :
: : s = ut + 0.5at*t
: : v = u + at
: : v*v = u*u + 2as
: :
: : For projectiles make sure you take time into consideration or else you won't get the right physics results. So every time step like every second or millesecond you will get the distance to move in the next frame. And if you take a = -g(i.e -9.8 or approx -10 if working with integers) then you get the falling down effect.
: :
: :
:
: Thanks, I didn't manage to get the time right before...
: But one problem with it, since a proccessor doesn't work on time, it works on clocks, and the process shares clocks with other processes, it's impossible to determine a time step without wait...
:
: What are v,a,t,s,u?
: Are they velocity, acceleration, time and length respectivly?
: And what is u then?
:
: I find english math very confusing sometimes, becouse they have a lot of other names in my native language, swedish...
:

Re: Help wanted on projectile equation for using in c++ Posted by IDK on 21 Aug 2006 at 9:03 AM
: Here goes the explanation then (my physics is a little rusty) -
: s = distance travelled
: u = initial velocity
: v = final velocity
: a = acceleration which is -g(if gravity comes into play)
:
: Time is the delta time (many times it is 0.016 which is 1/60 because of the 60 frames per second). You can also calculate this and then make use of it.
:
: So if I have s = ut + 0.5at*t when I start -> on x-axis u = 0, t = 0.016, a = v(from v = u + at and t = 1sec), thus s = ut + 0.5vt*t. On the y-axis you take gravity and hence a = -g into account. It goes something like this.
:
:
:
:
:

Thanks again, now I could actually make a real system that applies the real laws of physics in the right time.

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic