the object vector (m = the magnitude of the vector, A = angle of the vector) and a gravity vector (Gm, GA) the part i'm having trouble finding is the new angle it is much larger than it should be. I'm betting i'm doing something really stupid. GravityXY.x = Gm * sin(GA) ; GravityXY.y = Gm * cos(GA) ; XYVelocity.x = m * sin(A) ; XYVelocity.y = m * cos(A) ; ResultantMagnitude = sqrt( pow(XYVelocity.x + GravityXY.x, 2) + pow(XYVelocity.y + GravityXY.y, 2) ) ; ResultantAngle = atan( ( (XYVelocity.x + GravityXY.x) / (XYVelocity.y + GravityXY.y) ) ) ; |

# Vector addition

Started by asdfasdf, Jun 29 2001 09:44 AM

6 replies to this topic

###
#1
Members - Reputation: **122**

Posted 29 June 2001 - 09:44 AM

Alright, let me start off by saying...I suck at physics.
That said, I have a flying object with a constant velocity. Once this object is "shot" i need it to fall realistically.

thats basically my code ( edited for aesthetics )
Once again, physics confuses me SO PLEASE DON"T FLAME AND/OR RIDICULE ME.
Edited by - asdfasdf on June 29, 2001 4:46:10 PM
Edited by - asdfasdf on June 29, 2001 4:47:17 PM

###
#2
Members - Reputation: **116**

Posted 29 June 2001 - 10:06 AM

instead of using sin and cos functions, (which you can) why don''t you have an exponential type of function that falls realistically. since I suck aat physics, I''d have a counter, then enter the counter number (based on a timer) into my exponential function and find how much it should fall. have a real physics guy tell you how they''d do it.

HHSDrum@yahoo.com

Polarisoft Home Page

HHSDrum@yahoo.com

Polarisoft Home Page

###
#3
Members - Reputation: **929**

Posted 29 June 2001 - 10:35 AM

You could just have a gravity vector, and add that to the other vector to get a resultant vector that you should move the object by. Since the path of a moving falling object is a parabola, a parametric equation might be of some benefit here.

###
#5
Members - Reputation: **122**

Posted 29 June 2001 - 05:29 PM

i''d suggest you''re doing it wrong. if your object is to fall realistically, it doesn''t have constant velocity.

stick with cartesian coordinates and only figure out angles when you need ''em for something. for your object, keep a position vector ( pos_x , pos_y , pos_z ) and a velocity vector ( vel_x , vel_y , vel_z ). if you use the coordinate system as oriented in grady''s .gif, your acceleration vector (w/o wind resistance) will be ( 0.0 , -9.8 , 0.0 ) [for ( acc_x , acc_y , acc_z ) that is.]

now, to make it realistic, put in wind resistance. you can approximate it with

F_wind = -c*vel^2 where c is some constant and the (-) sign means that the force on the object is opposite the direction of v (F_wind and vel are vectors here). Once you figure out F_wind_x , F_wind_y , and F_wind_z , you can divide each of those by the mass of the object to get the components of acceleration and add those into ( acc_x , acc_y , acc_z ).

stick with cartesian coordinates and only figure out angles when you need ''em for something. for your object, keep a position vector ( pos_x , pos_y , pos_z ) and a velocity vector ( vel_x , vel_y , vel_z ). if you use the coordinate system as oriented in grady''s .gif, your acceleration vector (w/o wind resistance) will be ( 0.0 , -9.8 , 0.0 ) [for ( acc_x , acc_y , acc_z ) that is.]

now, to make it realistic, put in wind resistance. you can approximate it with

F_wind = -c*vel^2 where c is some constant and the (-) sign means that the force on the object is opposite the direction of v (F_wind and vel are vectors here). Once you figure out F_wind_x , F_wind_y , and F_wind_z , you can divide each of those by the mass of the object to get the components of acceleration and add those into ( acc_x , acc_y , acc_z ).

###
#6
Members - Reputation: **122**

Posted 29 June 2001 - 06:04 PM

If you have a starting velocity and an acceleration here''s an equaiton you might find useful.

s = (Vi * t) + 0.5 * a * t^2

''s'' is the displacement of an object from its starting point ''t'' seconds after it started off with ''Vi'' velocity and was influenced by ''a'' acceleration.

s = (Vi * t) + 0.5 * a * t^2

''s'' is the displacement of an object from its starting point ''t'' seconds after it started off with ''Vi'' velocity and was influenced by ''a'' acceleration.

###
#7
Members - Reputation: **122**

Posted 29 June 2001 - 06:29 PM

just do this:

struct Vector

{

float x, y;

};

Vector object_vel;

Vector object_pos;

Vector gravity;

void Launch_Object(Vector pos, float angle, float speed)

{

object_pos.x = pos.x;

object_pos.y = pos.y;

object_vel.x = sin(angle) * speed; // If this doesn''t work

object_vel.y = cos(angle) * speed; // then flip cos/sin

}

void Update_Object()

{

object_pos.x += object_vel.x;

object_pos.y += object_vel.y;

object_vel.x += gravity.x;

object_vel.y += gravity.y;

}

void main()

{

Vector v = {0, 0};

Launch_Object(v, .5, .5);

while(you_want_to_keep_moving_your_object)

{

Update_Object();

Draw_Object();

}

}

thats just psuedo-normal code, so it won''t compile, but that should give you an idea...

struct Vector

{

float x, y;

};

Vector object_vel;

Vector object_pos;

Vector gravity;

void Launch_Object(Vector pos, float angle, float speed)

{

object_pos.x = pos.x;

object_pos.y = pos.y;

object_vel.x = sin(angle) * speed; // If this doesn''t work

object_vel.y = cos(angle) * speed; // then flip cos/sin

}

void Update_Object()

{

object_pos.x += object_vel.x;

object_pos.y += object_vel.y;

object_vel.x += gravity.x;

object_vel.y += gravity.y;

}

void main()

{

Vector v = {0, 0};

Launch_Object(v, .5, .5);

while(you_want_to_keep_moving_your_object)

{

Update_Object();

Draw_Object();

}

}

thats just psuedo-normal code, so it won''t compile, but that should give you an idea...