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 & HelpOther Libraries › toxicLib verletphysics questions
Page Index Toggle Pages: 1
toxicLib verletphysics questions (Read 2349 times)
toxicLib verletphysics questions
Sep 20th, 2009, 5:45pm
 
For an upcoming project I have to work with a physic library creating elastic strings etc. Ive worked with traerphysics before but thought about switching to toxis verletphysic library as I am using some other of his libraries and believe it is a great library .

The only problem ive got is the lack of documentation and examples that makes it sometimes hard for me to understand and to use.
I used the "ThreadDemo" example he provides to start with and get used to it before starting the project.

But some questions popped up that i just can't answer reading the doc : https://dev.postspectacular.com/docs/verletphysics/

So I will make a list of them and would be happy about every question answered. If somebody have or know some simple examples that would help to understand, I am also thankful for them.

Using the example the "thread" behaves like a rubber band. I wanted to make it more like a chain. So instead of springs add something like sticks that keep particles at a given distance.
I tried to change the strength value when creating the springs :

physics.addSpring(new VerletSpring2D(prev,p,REST_LENGTH,STRENGTH)); it seems to be a value between 0 and 1 as anything over 1 is just a mess. Anyway it seems to be more elastic close to 0 but even when I make it 1 its still not rigid. How to I set the Maximum distance?

I noticed there are different springs, called VerletConstrainedSpring2D
& VerletMinDistanceSpring2D but I got almost the same results. So I am asking myself where is the difference between them, and how do I use them. Do I have to add more then 1 spring to the particles or have to decide witch one to use? In trear physic its pretty easy, I just don't get how it works here.

Something else I know from traer physics. Where or how exactly do I set forces? I want to add a force ( a single particle in this case) attracting or pushing away other particles. Is this possible at all?

Using traer physics it was possible to set tick() to make the animation goe faster or much slower to get a slow motion effect. That was pretty useful.  I first thought it could be "public float timeStep" but it doesn't seems to change the time, it looks more like changing the friction.

That brings me to the next question. Friction. What is the range here? Had to set it really high, 10.000 to make look hard to pull. But here it would be even more possible to make the Spring less elastic cause .

Another question. What exactly is numIterations, (iterations for verlet solver) it also looks more like it is chaning the strength of the springs

I guess thats it for now. I really would like to use all the libraries more often but I am having a hard time understanding...
Hope somebody can shed some light on it.


Re: toxicLib verletphysics questions
Reply #1 - Sep 20th, 2009, 5:57pm
 
Here is the example code if you wanna test or explain. +


Code:
import processing.opengl.*;

import toxi.physics2d.constraints.*;
import toxi.physics2d.*;

import toxi.geom.*;
import toxi.math.*;

int NUM_PARTICLES = 22;
int REST_LENGTH=10;

VerletPhysics2D physics;
VerletParticle2D head,tail;

boolean isTailLocked;

void setup() {
size(1024,768,OPENGL);
smooth();

background(255);
physics=new VerletPhysics2D();

//physics.numIterations = 1 ;
VerletParticle2D prev=null;

for(int i=0; i<NUM_PARTICLES; i++) {
VerletParticle2D p=new VerletParticle2D(new Vec2D(width/2,height/2));
physics.addParticle(p);
if (prev!=null) {

physics.addSpring(new VerletSpring2D(prev,p,REST_LENGTH,1));

}
prev=p;
}




tail=prev;
head=physics.particles.get(1);
head.lock();
}

void draw() {
background(255);
stroke(0,100);
noFill();
head.set(mouseX,mouseY);
physics.update();
beginShape();

for(Iterator i=physics.particles.iterator(); i.hasNext();) {
VerletParticle2D p=(VerletParticle2D)i.next();
vertex(p.x,p.y);
}
endShape();

for(Iterator i=physics.particles.iterator(); i.hasNext();) {
VerletParticle2D p=(VerletParticle2D)i.next();
ellipse(p.x ,p.y,5,5);
}
}

void mousePressed() {
isTailLocked=!isTailLocked;
if (isTailLocked) {
tail.lock();
}
else {
tail.unlock();
}
}

Re: toxicLib verletphysics questions
Reply #2 - Sep 27th, 2009, 7:10am
 
Hmm to bad, but I guess i stay with traerphysics for now.
Re: toxicLib verletphysics questions
Reply #3 - Sep 28th, 2009, 8:17am
 
I wanted to try this library for quite some time, having the archive, but it was not installed yet.
So you motivated me to install it (v.0004 with core v.0014) and try the demo.

First, I am surprised because unlike what you describe, the links of the ThreadDemo are rigid: if I reduce them to 20 and set their length to 50, I don't see their length to change.

Second, I am slightly annoyed as I tried to customize look of particles, but found out that isLocked field is protected and has no getter... Another annoyance, in the doc, is that 2D stuff (Vec2D, Xxx2D) is made out of the 3D stuff. The parameter list (for example) has changed, but not the JavaDoc!

I tried, like you, to play with the strength parameter. It worked fine up to a value of 2.0, after that I have a ball of thread. Looks like at low values the thread is more flexible, at higher values it is more rigid.

Forces: you can set the gravity, for example. Looking at the source of VerletPhysics2D, I see it is applied on each particle on each iteration.
You can use a similar method, inspired by code seen at FidGen.pde:
Code:
Iterator ip = physics.particles.iterator();
while (ip.hasNext()) {
VerletParticle2D p = (VerletParticle2D) ip.next();
p.addSelf(force.scale(p.weight));
}

where force is a Vec2D. Well, in the gravity code, there is a test on !p.isLocked but Processing sketches doesn't have access to this field... Sad

You can also define constraints yourself.

Set tick(). The tick of this physics system seems to be entirely driven by calls to physics.update();. So if you want a slow motion effect, just call it every n draw() calls.

friction and timeStep: from what I see, the force applied to particles depends on friction multiplied by the squared timeStep:
float force = 1.0f - friction * timeStep * timeStep;
So I think both parameters are designed to be below 1.

numIterations, if I understood correctly, acts on the quality of the simulation: the higher the number, the better the simulation, at the cost of CPU power!

I think traer's and toxic's physics engines have slightly different aims.
toxics seems to use it mostly for blob simulation (like in the fiducial or Nokia demos), filling a shape with a number of particles and lot of springs between them.
They use different integration systems (Verlet vs. Runge-Kutta (or Euler)), with different stability issues.

So these libraries seem more complementary than being a replacement for each other.
Now, I am not a specialist of the field, so if I wrote anything wrong or inaccurate above, please correct me.
Re: toxicLib verletphysics questions
Reply #4 - Nov 15th, 2009, 10:07am
 
Hi Cedric & PhiLho, I've just stumbled across this thread now... Somehow I'm a bit surprised by the general discussions & issues about toxiclibs on this forum. As I explained in another thread to which you also replied, I'm well aware about the lack of documentation and just like any other piece of software, I know these libraries have some bugs and other issues, which I'm doing my best to resolve all the time. What I don't quite understand is, why if you're having issues, no one is getting in touch about such things! I've explained here a few times previously that I don't have time to monitor this forum here for any issues and so this is not the best place to talk about these libs. But there's a mailing list to get answers and also an issue tracker on Google code to log any problems... you can also get in touch personally, I won't bite! Smiley
Re: toxicLib verletphysics questions
Reply #5 - Nov 16th, 2009, 4:09pm
 
hey toxi, thanks for coming back to this thread.
As i am quite active in this forum, i know that the help you get from other people is really good and fast. As i answer a lot of questions here i know that most questions could be answered by searching the forum. so i always think its a good way to document questions and answers somewhere. And as we have seen there are some questions regarding verletphysics recently.

Another simple reason why i didnt contact you is, that i know that you are really busy with your work and I i didnt  want to bother you with questions if not really necessary.

But thanks for pointing out the issue tracker and the mailing list and for offering support. I am really thankful for your overall contribution to the processing community!
Page Index Toggle Pages: 1