Calculating Final Positions & Velocities for M1, M2 & Spring After DeltaT

Click For Summary

Discussion Overview

The discussion revolves around calculating the final positions and velocities of two masses connected by a spring after a specified time increment (deltaT). It explores the dynamics of a mass-spring-mass system, particularly in the context of simulating collisions for a real-time audio synthesizer. The focus is on numerical methods for solving the equations of motion rather than analytical solutions.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant describes the setup of two masses and a spring, defining various parameters related to their positions and velocities.
  • Another participant suggests that including mass in the spring complicates the problem and recommends avoiding it if possible.
  • There is a discussion about the necessity of calculus and differential equations for solving the motion of the masses.
  • Participants explore the option of using numerical solutions, with one suggesting Euler’s method for calculations.
  • Concerns are raised about the accuracy of the simulation, particularly regarding the rapid movement of the hammer relative to the sample rate, which could lead to unrealistic spring behavior.
  • One participant outlines a proposed numerical approach, detailing how to increment positions and calculate forces at each step.
  • Follow-up questions are posed regarding the application of spring force to both masses and the implementation of damping in the spring's behavior.
  • There is a query about the correct interpretation of the damping equation and how to integrate it into the solution.

Areas of Agreement / Disagreement

Participants generally agree on the complexity of the problem and the preference for numerical solutions. However, there are multiple views regarding the specifics of implementing the spring force and damping, and no consensus is reached on the best approach to these aspects.

Contextual Notes

Participants express uncertainty about the effects of rapid movements on the spring's behavior and the implications of using different methods for calculating forces and damping. The discussion highlights the need for careful consideration of the parameters involved in the simulation.

Who May Find This Useful

This discussion may be useful for individuals interested in simulating physical systems involving springs and masses, particularly in the context of audio synthesis or real-time simulations. It may also benefit those looking to understand numerical methods for solving differential equations in physics.

mikejm
Messages
40
Reaction score
2
Let's say you have two masses on either side of a spring. Mass 1 is connected to the end of a spring. The spring itself has no mass. Mass 2 is free in space. So you have:

Code:
[M1]-[spring]           [M2]
So it's more descriptive, I'll name the variables like you might in programming. Let's define each element as follows.

Mass 1:
  • m1Mass = mass of M1
  • m1PosInit = initial position of M1
  • m1PosFinal = final position of M1
  • m1VelInit = initial velocity of M1
  • m1VelFinal = final velocity of M1

Mass 2:
  • m2Mass = mass of M2
  • m2PosInit = initial position of M2
  • m2PosFinal = final position of M2
  • m2VelInit = initial velocity of M2
  • m2VelFinal = final velocity of M2
Spring:
  • springLengthAtRest = natural length of spring when not compressed at rest
  • springLengthInit = initial length of spring
  • springLengthFinal = final length of spring
  • springCompressionInit = springLengthAtRest - springLengthInit
  • springCompressionFinal = springLengthAtRest - springLengthFinal
  • springForce = force of the nonlinear spring based on spring compression (eg. from a simple equation like F(x) = -k x^{c})

Time:
  • deltaT = amount of time that passes from initial state to final state

At the initial state, mass 2 is already in contact with the end of the spring (or is just about to contact it) with a given momentum. Mass 1 is traveling with a given momentum as well. The spring has a given amount of initial compression (which could be zero or non-zero).

How do you calculate the final positions and velocities after a certain increment of time (deltaT) for all the elements?

I'm trying to simulate a collision in a program I'm writing just for fun but stuck on this. If it's easier to give the spring some mass that's fine too. Whatever works. Thanks a bunch.
 
Last edited:
Physics news on Phys.org
The problem is appreciably harder if the spring has some mass - don’t do that if you can avoid it.

How much calculus do you know? The equations for the position and velocity of each mass are the solutions to differential equations.
 
Nugatory said:
The problem is appreciably harder if the spring has some mass - don’t do that if you can avoid it.

How much calculus do you know? The equations for the position and velocity of each mass are the solutions to differential equations.

Thanks. Yeah I was figuring giving the spring mass would make it much harder. We'll leave it with no mass then.

I can try to know as much as I need to know. :smile: I never knew how to do imaginary math with Euler's formula or Laplace transforms last year and now to a limited extent I can (had to learn similarly to solve some problems). Two years ago I didn't know a line of C++ and now I code freely. I need to solve this problem now or my program design is stuck on it. So it's non-negotiable for me to figure it out.

I have looked at as many websites and textbook examples as I can for collisions but they all only talk about mass-mass, not mass-spring-mass. Also most don't focus on the goal of finding the resulting positions/momentums after a given increment of time from an initial given state.

Without any further help or direction I'm totally stuck on this. Any help or guidance would be very much appreciated.
 
Do you need an analytical solution or are numerical solutions ok?
 
Dale said:
Do you need an analytical solution or are numerical solutions ok?
Numerical is totally fine and probably desirable!

FYI, if you're curious, this is for simulating the collision of a piano hammer or guitar plectrum (both of which are typically modeled as a mass (ie. hand/hammer) connected to a spring (ie. plectrum/felt) impacting another mass (ie. string segment)). It's a real time audio synthesiser I'm designing that needs to be calculated sample-by-sample so it needs to be efficient and doesn't need to be exactly precise.

Thanks.
 
mikejm said:
It's a real time audio synthesiser I'm designing that needs to be calculated sample-by-sample so it needs to be efficient and doesn't need to be exactly precise.
Then you should probably calculate it numerically using something like Euler’s method.

Basically, you know the initial positions, velocities, and forces, and with any set of positions you can calculate the forces. So you break your time into small steps, maybe 1/10 of a sample or less. Then ##t_n=n * dt## and then you calculate the next steps based on the current values:
##x(t_{n+1})=x(t_n)+v(t_n)dt ##
##v(t_{n+1})=v(t_n)+F(t_n,x_n,...)dt/m##
 
Dale said:
Then you should probably calculate it numerically using something like Euler’s method.

Basically, you know the initial positions, velocities, and forces, and with any set of positions you can calculate the forces. So you break your time into small steps, maybe 1/10 of a sample or less. Then tn=n∗dt and then you calculate the next steps based on the current values:
x(tn+1)=x(tn)+v(tn)dt
v(tn+1)=v(tn)+F(tn,xn,...)dt/m

Thanks Dale. That's sort of what I tried doing already but I didn't think about the possibility of doing it with even finer detail than per sample in the way you suggest. The problem is the "hammer/hand" was moving so quickly relative to the sample rate it was collapsing the spring almost fully on the first contact which then threw things off because in reality the spring force would have prevented such a great collapse. I was ending up with major spring collapses with massive spring forces that never would have been generated in real life.

So I will at each step:
  • Increment the two masses' positions based on their velocities.
  • Calculate the force of the spring based on their new positions.
  • Calculate their new velocities based on their old velocity and the spring force.
I can subdivide the sample into enough increments to get this done with finer detail to avoid the problem I'm having. Thanks that's really really helpful and I never would have thought of "oversampling" in this way to fix the problem. I also wasn't sure if my method I was already using was correct - I just thought it made sense and was making it up as I went. Glad to hear it's actually the right way to deal with it. :smile:

Can I ask you just two small follow up questions?

Spring force when calculated by compression as in F(x) = kx^c (where x is total amount of spring compression) is applied equally to both masses right? Ie. It's not divided into 2 is it and half applied to one mass, half to the other?

Also, how would I implement damping on my spring if I wanted to? I understand springs can oscillate if not damped. It shouldn't oscillate in my case because the spring/hammer/plectrum will release quickly then be reset, but I'm just curious. I think the equation for a nonlinear damped spring is:

F(x) = k*x^c - d*v

Where k is the spring constant, c is a constant for the nonlinear property, and d is a damping coefficient. Is this typically correct?

If so, how would I integrate that into the solution? What exactly does the "v" term represent velocity of?

Would the "v" term be based on the velocity of the mass at that end? Or the velocity of one mass minus the other to get the "net" velocity? Would it be the same for both masses or different?

Thanks again. You've been super helpful.
 
Last edited:

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
Replies
20
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 37 ·
2
Replies
37
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 19 ·
Replies
19
Views
3K
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K