Help with physics
Re: Help with physics
nothing adds anything by itself unless you write a program that will do it.
You may use my provided function and increase x in each loop if you want to calculate y based on x,
and you may use DaA's function and increase t in each loop if you want to calculate x and y (x,y) based on t.
g is a physical constant, called gravitational acceleration.
It is g=9.81 m/s²
http://en.wikipedia.org/wiki/Gravitational_acceleration
Sorry, I can't explain the mathematical/physical principles (in Germany kids learn that stuff at grammar school, when they are about 13/14 years old , IIRC).
I can only tell you what's the formula (function) like, to understand it I think you have to read a physics textbook.
You may use my provided function and increase x in each loop if you want to calculate y based on x,
and you may use DaA's function and increase t in each loop if you want to calculate x and y (x,y) based on t.
g is a physical constant, called gravitational acceleration.
It is g=9.81 m/s²
http://en.wikipedia.org/wiki/Gravitational_acceleration
Sorry, I can't explain the mathematical/physical principles (in Germany kids learn that stuff at grammar school, when they are about 13/14 years old , IIRC).
I can only tell you what's the formula (function) like, to understand it I think you have to read a physics textbook.
Re: Help with physics
Here is the code and .rxe for shooting. I think it will shoot at 40 degrees.
- Attachments
-
- shoot.zip
- (642 Bytes) Downloaded 274 times
Thanks, and have a nice day,
nxtboy III
programnxt.com
nxtboy III
programnxt.com
Re: Help with physics
I tried all the things you guys posted, but none of them work.
Thanks, and have a nice day,
nxtboy III
programnxt.com
nxtboy III
programnxt.com
Re: Help with physics
Using the code Doc posted (based on DaA):
We go like this:
Notice I used sind() and cosd(), so the input is in degrees. With sin() and cos(), the input is in radians.
I recommend using this version, though:
EDIT: I fixed the code above. (The `Y += ...;` part. And the messed up #TIME_STEP)
This is what happens when LaTeX is not used.
Code: Select all
X = X_start+V*cos(Angle)*time
Y= Y_start+V*sin(Angle)*time-.5*g*time^2
Code: Select all
#define g 10
#define TIME_STEP 100
int X_start = 20;
int Y_start = 0;
int X;
int Y;
int angle = 40;
long V = 5; // pixels per second
for(long time = 0; 1; time += TIME_STEP)
{
X = X_start + V*cosd(angle)*time/1000;
Y = Y_start + V*sind(angle)*time/1000 - g*time*time/1000/1000/2;
if(Y < Y_start)
break;
// Draw
CircleOut(X, Y, 3, DRAW_OPT_FILL_SHAPE);
}
I recommend using this version, though:
Code: Select all
#define g 10
#define TIME_STEP 100
int X_start = 20;
int Y_start = 0;
int X = X_start;
int Y = Y_start;
int angle = 40;
long V = 5; // pixels per second
for(long time = 0; 1; time += TIME_STEP)
{
X += V*cosd(angle)*(TIME_STEP)/1000;
Y += (V*sind(angle) - g)*(TIME_STEP)/1000;
if(Y < Y_start)
break;
// Draw
CircleOut(X, Y, 3, DRAW_OPT_FILL_SHAPE);
}
This is what happens when LaTeX is not used.
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
-
- Posts: 26
- Joined: 12 Oct 2010, 08:19
Re: Help with physics
Hello nxtboyiii
Each loop will probably need a time delay so the "projectile" doesn't go too fast.
The number for gravity would be 9.8 if the units are meters per second squared.
If you are using pixels (or anything else) for the length then gravity will be a different number (like 32.2 for feet per second squared).
I would recommend making an initial guess for the variables and adjusting them based on how the display looks.
Make the gravity value bigger to get the projectile to drop faster (but I'm sure you already knew that).
Dave
Anything can be added to X each time it loops.Does X just add 1 each time it loops?
If not, what does it add?
What should the gravity be?
Each loop will probably need a time delay so the "projectile" doesn't go too fast.
The number for gravity would be 9.8 if the units are meters per second squared.
If you are using pixels (or anything else) for the length then gravity will be a different number (like 32.2 for feet per second squared).
I would recommend making an initial guess for the variables and adjusting them based on how the display looks.
Make the gravity value bigger to get the projectile to drop faster (but I'm sure you already knew that).
What specifically doesn't work? Do you get anything on the display at all?I tried all the things you guys posted, but none of them work.
Dave
Re: Help with physics
I have a working version!!
Can someone improve it at all?
It is based on muntoo's version.
Anyways,
Can someone improve it at all?
It is based on muntoo's version.
Anyways,
Code: Select all
#define STARTING_POWER 20
#define AIR_RESISTANCE 0
#define GRAVITY 0
#define GRAVITY2 0.2
#define GROUND 0
float x = 50;
float y = 20;
float s=3;
byte power;
task main()
{
int Angle=Random(130);
float dx = cosd(Angle);
float dy = sind(Angle);
power=STARTING_POWER;
while(1)
{
x += dx;
y += dy;
if(power != 0)
{
power--;
}
else
{
dy-=GRAVITY2;
}
if(x > 0)
{
x -= AIR_RESISTANCE;
if(x < 0)
{
x = 0;
}
}
else if(x < 0)
{
x += AIR_RESISTANCE;
if(x > 0)
{
x = 0;
}
}
y -= GRAVITY;
if(y <= GROUND)
{
y = GROUND;
//Explosion
break;
}
RectOut(x,y,2,2);
Wait(30);
ClearScreen();
}
Wait(3000);
}
Thanks, and have a nice day,
nxtboy III
programnxt.com
nxtboy III
programnxt.com
Re: Help with physics
BTW, here's a good tutorial for Game Physics. It's very easy to understand, even for beginners. (The first/second ones, at least.)
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
Re: Help with physics
muntoo,muntoo wrote:BTW, here's a good tutorial for Game Physics.
have you honestly ever implemented RK4 (Runge Kutta order 4 integrator) by using NXC? I'm really curious to see your code!
Who is online
Users browsing this forum: No registered users and 1 guest