Spring Walkthrough for Programmers Struggling With Math

  • Thread starter mctuble
  • Start date
  • Tags
    Spring
In summary, you will need to use vector equations and distance formulas to calculate the force and velocity between the two points connected by the spring in order to determine the position for the next iteration.
  • #1
mctuble
1
0
I'm a programmer who loves math but unfortunately is not all that good at it. I'm trying to model a simple spring to be used as a form of suspension later on. Imagine I have:

Vector* p1;
Vector* p2;

float restLength;
float damping;
float stiff;

p1 and p2 obviously being vectors holding x and y coordinates for each along with a mass variable for each. The other three are pretty self explanatory

So I know Force = -stiff * distance(p1,p2) - damping * v

I have a bunch of questions about that. Is Force a vector? if so does that mean I wouldn't use the distance formula to find the distance? instead just subtract the x's and y's and put that in a vector? Also I'm confused as to what v is... I read its "v is the relative velocity between the two points connected by the spring" which I don't quite understand.

So bottom line is I want to take 2 points connected with a spring, each with potentially a different mass and with variables for restLength, damping, and stiffness and calculate the position of the spring for the next iteration.

If someone could walk me through this while breaking down the math to the basics (preferably without the mention of a vector) I'd be very thankful. I can understand the basic concept of what is happening I just can't understand the formulas that well. I've searched every site I can find but I can't really get off the ground. Please help. Thanks in advance.
 
Physics news on Phys.org
  • #2
The force equation you provided is a vector equation, meaning that it is composed of two components (x and y). The distance between the two points, p1 and p2, is also a vector, so you would need to use the vector distance formula to calculate it. The velocity, v, is the relative velocity between the two points connected by the spring. This means that you would need to calculate the velocity of each point relative to the other. To do this, you would need to calculate the difference between the positions of the two points in the previous iteration and the current iteration, and then divide this by the time step. Once you have all these values, you can calculate the force vector on each point, which will give you the direction and magnitude of the force. You can then use this force to calculate the acceleration of each point, and then the new position for each point in the next iteration.
 
  • #3


I understand that math can be challenging for some individuals, but it is an important tool in many fields, including programming. It is great that you have a love for math and are trying to improve your skills. I am happy to assist you in understanding the concepts behind your spring model.

First, let's start with the formula you provided: Force = -stiff * distance(p1,p2) - damping * v. This is known as Hooke's Law, which describes the force exerted by a spring. Yes, Force is a vector quantity, meaning it has both magnitude and direction. In this case, it represents the force exerted by the spring on the two points, p1 and p2.

The distance formula is used to find the distance between the two points, which is necessary in calculating the force exerted by the spring. So, you would still use the distance formula to find the distance between p1 and p2.

Now, let's talk about v. In this formula, v represents the relative velocity between the two points connected by the spring. Velocity is a vector quantity that describes the rate of change of an object's position. In this case, v represents the speed and direction at which the two points are moving towards or away from each other. This is important in calculating the damping force, which is the force that opposes the motion of the two points.

To break down the formula even further, let's look at each term individually. The first term, -stiff * distance(p1,p2), represents the spring force, which is directly proportional to the distance between the two points. This means that the farther apart the two points are, the stronger the force exerted by the spring will be. The stiffness (or spring constant) is a property of the spring and determines how much force is needed to stretch or compress it.

The second term, -damping * v, represents the damping force, which is directly proportional to the relative velocity between the two points. This means that the faster the two points are moving towards or away from each other, the stronger the damping force will be. Damping is a property of the medium in which the two points are moving and can be thought of as resistance to motion.

To calculate the position of the spring for the next iteration, you would need to use the equations of motion, specifically Newton's second law (F=ma) and the kinematic equations to determine
 

FAQ: Spring Walkthrough for Programmers Struggling With Math

What is the purpose of the "Spring Walkthrough for Programmers Struggling With Math"?

The purpose of the walkthrough is to provide programmers with a step-by-step guide for understanding and applying mathematical concepts that are commonly used in programming.

Who is the target audience for this walkthrough?

The target audience is programmers who may not have a strong mathematics background and are struggling to understand and use mathematical concepts in their code.

What topics are covered in the "Spring Walkthrough for Programmers Struggling With Math"?

The walkthrough covers topics such as algebra, geometry, trigonometry, and calculus, as well as how these concepts can be applied in programming.

Is this walkthrough suitable for all levels of programming experience?

Yes, the walkthrough is designed to be helpful for programmers at all levels of experience. It starts with basic concepts and builds upon them, making it useful for beginners as well as more experienced programmers.

How can this walkthrough benefit me as a programmer?

This walkthrough can help you improve your understanding and application of mathematical concepts in programming, which can lead to more efficient and accurate code. It can also broaden your knowledge and skills, making you a more well-rounded programmer.

Back
Top