Rectangular Vectors From angle and magnitude

In summary, the conversation is about programming a game that uses planetary gravity to make a spaceship orbit. The project is going well, but there are some issues with the details of the code and the formulas being used. Suggestions are made to improve the calculations for force, acceleration, velocity, and position.
  • #1
steakbbq
1
0
Not really homework. But I am programming a game. It is using planetary gravity to make a spaceship go into orbit. I have it so that I find the magnitude of gravity and the direction the planet is in from the ship. I need to make gravity act on the ship in the direction of the planet.

I thin it is something like.

Xpos = cos(angle) + xvelocity;
YPos = sin(angle) + yvelocity;

my head hurts. I can post some of the code to see if you can make sense of it.


//Clalculate Force Of Gravity
forceOfGravity = 1 * ((shipMass * earthMass)/Math.pow(distanceEarth,2));
//Calculate Acceleration
acceleration = forceOfGravity * shipMass;
//Calculate Final Velocity;
fVelocityX = iVelocityX + acceleration * timeStep;
fVelocityY = iVelocityY + acceleration * timeStep;
//Calculate Final Position;
fPositionX = iPositionX + velocity * timeStep;
fPositionY = iPositionY + velocity * timeStep;
//Calculate The X and Y Coordinates Based On Velocity And Angle
//this.x = Math.cos(angleRads);
//this.y = Math.sin(angleRads);
 
Physics news on Phys.org
  • #2
Welcome to PF, Steakbbq!
Your project sounds most interesting. It looks like you have the big picture of the main loop set up well.

But there are problems with the details. At
"fVelocityX = iVelocityX + acceleration * timeStep;"
it is already necessary to know the direction of the acceleration, and use only the x component to find the change in the x component of velocity. Better to find the x and y components of acceleration before doing the velocities. For the position calcs, use only the x component of velocity in the calculation of the x position.

Those formulas at the beginning, Xpos = cos(angle) + xvelocity;,
do not make sense because Xpos has units of meters, the cos term has no units and the velocity term has units of m/s.
 

1. What is a rectangular vector?

A rectangular vector is a graphical representation of a physical quantity, such as velocity or force, that has both magnitude and direction. It is typically represented by an arrow pointing in the direction of the vector with a length proportional to its magnitude.

2. How do you find the components of a rectangular vector from angle and magnitude?

To find the components of a rectangular vector from angle and magnitude, you can use the trigonometric functions sine and cosine. The x-component is equal to the magnitude multiplied by the cosine of the angle, and the y-component is equal to the magnitude multiplied by the sine of the angle.

3. Can a rectangular vector have a negative magnitude?

Yes, a rectangular vector can have a negative magnitude. This indicates that the vector is pointing in the opposite direction of its positive counterpart. For example, a velocity vector with a magnitude of -5 m/s would be pointing in the negative direction of its axis.

4. How do you add or subtract rectangular vectors?

To add or subtract rectangular vectors, you can use the head-to-tail method. This involves placing the second vector's tail at the head of the first vector and drawing a line from the tail of the first vector to the head of the second vector. The resulting vector from the tail of the first vector to the head of the second vector is the sum or difference of the two vectors.

5. Can a rectangular vector have a magnitude of zero?

Yes, a rectangular vector can have a magnitude of zero. This means that the vector has no length and no direction, and is often referred to as the zero vector or null vector. It is represented by a point at the origin of the coordinate system.

Similar threads

  • Introductory Physics Homework Help
Replies
1
Views
2K
  • Programming and Computer Science
Replies
4
Views
5K
  • Programming and Computer Science
Replies
5
Views
2K
Replies
2
Views
2K
Back
Top