We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › gradient descent to a spring system
Page Index Toggle Pages: 1
gradient descent to a spring system (Read 477 times)
gradient descent to a spring system
Aug 6th, 2008, 5:20pm
 
hi,

I'm pretty new to processing and I would like to include into my program an adaptation of a gradient descent.
I have a spring system; I find each time two points and then I am trying to connect them with a spring, which according to the initial distance between the two points will try to reach one out of three possible lengths. The thing is, that instead of having "if" clauses, I want to differentiate the strength and the possibility of each of the three lengths' occurence..

It would be greatly appreciated if anyone could offer any piece of advice.

thanks!


a part of pseudocode is included:


//....
//float drive=1.5; // the ideal length
//
class Spring
{
 Node node1;
 Node node2;
 float d;  // the each time nodes' distance
 //...

 Spring(Node nodei, Node nodej)
 {
   node1 = nodei;
   node2 = nodej;
 }


 void create()
 {
   Vec now1;
   Vec now2;

   d = disto (now1,now2);  

   //...
   if (d<0.9*drive)    
   {
     d = (drive * 0.4)-d;
   }

   if (d>1.5*drive)    
   {
     d = (drive*1.01)-d;                        
   }

   if (d>=0.9*drive && d<=1.5*drive)        
   {
     d=drive-d;    
   }
   //...
 }
 //...
}
Re: gradient descent to a spring system
Reply #1 - Aug 7th, 2008, 11:16am
 
Just so you know, there are already two physics libraries: traer physics, mostly to do springs and particle systems (I think) and JBox2D, more complete.

If you prefer to do this yourself (for fun, learning or compactness), no problem.

But I fear I don't understand your problem/question.
Note: I would put else if in the successive tests, to avoid changing d several times, unless it is really what you need to do.
Re: gradient descent to a spring system
Reply #2 - Aug 7th, 2008, 7:35pm
 
Thanks for the advice!
I'll search for the libraries. Actually I am not using them  for experimenting reasons and I think I found an easy way to do so..But there are some parts, like some unwanted line crossings that need to be figured out..
Page Index Toggle Pages: 1