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 › how to get all springs connected to particle,traer
Page Index Toggle Pages: 1
how to get all springs connected to particle,traer (Read 282 times)
how to get all springs connected to particle,traer
Feb 28th, 2009, 8:49pm
 
Hi
I'm working with traer's physics library and I'm wondering if anyone knows of an easy way to get all those springs connected to a particular particle. Nothing appears immediately available - I think I might need to write another class, but I would prefer not to

thanks!
Re: how to get all springs connected to particle,t
Reply #1 - Mar 1st, 2009, 5:10am
 
When you create springs in traer.physics, they inherently connect to two EXISTING particles.  If you delete a particle, I believe that any associated springs (or attractions) are automatically removed for you.

So you can't, as it were, "hook all the springs up to a given particle".

It's also a little weird that you can't, as I recall, actually delete a spring or an attraction.  The best you can do is to disable them (turn them off if you don't want them active anymore).

What you can do, however, is create a new point (or in your case, it sounds like, just pick one of your existing points), loop over all the old (other) points, and create new springs connecting each old point to the new point.
Re: how to get all springs connected to particle,t
Reply #2 - Mar 1st, 2009, 9:36pm
 
hey cloister
I really appreciate your response. I think the way I worded my question may have led you in the wrong direction. What I meant by "get all springs connected" was not about making connections but about discovering existing ones. The "get" part would be about assembling a list of those springs emanating from a user specified particle so that some operation could be performed on them. I just wanted to be able to click on a particle and draw its springs differently.

i have a bit of a head cold though so maybe I'm just not getting what you're saying...thanks for the help
o
Re: how to get all springs connected to particle,t
Reply #3 - Mar 2nd, 2009, 11:35am
 
If traer doesn't provide this information, I suppose you have to track yourself the connections you are adding.
Re: how to get all springs connected to particle,t
Reply #4 - Mar 3rd, 2009, 12:15am
 
Oh.  Springs and Attractions, if memory serves, have a couple of methods ".getOneEnd()" and ".getTheOtherEnd()" which return either the Particle objects they're connected to, or the numerical indexes of the Particles they're connected to.  One or the other.  From there, it's pretty easy to use traer's global Particles collection to get the one you want.
Re: how to get all springs connected to particle,t
Reply #5 - Mar 3rd, 2009, 7:24pm
 
I wanted the spring attached to the particle and that function seems to be a method of the spring class. I wanted to literally pick (mouseclick) a particle, and redraw an attached spring in a different weight or colour. The Particle getOneEnd() or getTheOtherEnd() seems to me to need to start with the spring, and not the particle...
Re: how to get all springs connected to particle,t
Reply #6 - Mar 3rd, 2009, 9:11pm
 
If you loop through all the springs you can check both ends of each spring to find all that join to a specified particle:

Code:
for(int i=0;i<physics.numberOfSprings();i++)
{
Spring s=physics.getSpring(i);
if(s.getOneEnd()==myParticle || s.getTheOtherEnd()==myPArticle)
{
//do something....
}
}
Page Index Toggle Pages: 1