Struggling to create a 2-dimensional spring

lucas boutignon's icon

Hello ! I've been trying to simulate mass-spring-damper models in max. i managed to come up with a one dimensional spring that works well . however, when I'm trying to make it 2-dimensional, there is an issue: when the output is reaching the input position, it's moving faster in diagonal (from 0,0 to 1,1 for exemple) compared to when it's moving horizontally or vertically. in the patch, this model correspond to model 1.

to solve this issue, i tried in model 2 to calculate the distance between the output and input position, and then dividing the speed value by the distance. And it works ! however, now i can't seem to find any solutions in order to add a damping parameter like in model 1. when i try to merge model 1 and 2, in all kinds of possible ways, i never manage to get a proper spring behavior.

basically , I'm trying to make a two-dimensional version of model 1. does anyone know a way to achieve this ? thank you.

lucas boutignon's icon

forgot the patch :

Max Patch
Copy patch and select New From Clipboard in Max.

Roman Thilenius's icon

i know this problem but i dont know the solution. however if you find that distance is not 100% what you are looking for, try angle, or try squaring the values ... something like that is it.^^

lucas boutignon's icon

yes i've been looking at those solutions recently. Apparently i should multiply the X by sin and Y by cosine... also i've been trying to normalize the vectors ? if i understand that notion correctly, if the spring goes from (0,0) to (1,1) , i should create a spring that goes from 0 to sqrt(1+1), so from 0 to 1.4 . then i scale that motion between the correct values, 0 and 1. But no luck achieving this idea so far.
Also, do you have any idea on the name of the algorithm I'm using ? I'm pretty sure that the word I'm using to define the parameters are not correct (speed, delay and feedback) it seems i should be using damping, stiffness, etc. I'm not even sure if my system is indeed a spring- mass-damper system. it seems more like a "closed loop control system" .
also , in the gen object's help file , there is an object called "simple lowpass". this gen patch is actually the same algorithm as mine without the feedback, written in gen.