Jump to content

The correct way to handle collisions?


Lucy Coleclough

Recommended Posts

Hi there. 

I am currently building a cloth solver and have just got onto external collision handling. For internal collision I am using the same pbd approach they show off in the grains masterclass.

I thought I would go about external collisions a similar way, using a gas collision detect 

I get the incidence vector and reflect it. Then add the resulting reflected vector to the position.

if (i@hitnum)
{
    vector incidence= v@hitpos-v@P;
    float mag=length(incidence);
    vector reflection= reflect(normalize(incidence), normalize(v@hitnml));
    v@P+=reflection*mag;
}

The cloth still blows up, even at a high substep

Annoyingly a simple

if (i@hitnum)
    v@P=v@hitpos;

seems to work worlds better albeit the colliding points get stuck in place (which is something I aimed to fix by setting the new position to the reflected vector). The reason I'm not using the gas integrator to handle this for me is because I was looking to learn how this system is implemented.

What is the correct way to go about this?

As always any help is greatly appreciated

Thanks :)

Link to comment
Share on other sites

Someone else might be better with the math and code. But I'm not. Please post a minimalist version of your hip file so myself and others can have a chance to play with it until it's right and get back to you with an answer.

Barring that you may want to integrate your collision with an acceleration or a velocity change instead of a straight position change. And/or put a acceleration/velocity limiter in there too.

Edited by kleer001
Link to comment
Share on other sites

14 hours ago, kleer001 said:

Someone else might be better with the math and code. But I'm not. Please post a minimalist version of your hip file so myself and others can have a chance to play with it until it's right and get back to you with an answer.

Barring that you may want to integrate your collision with an acceleration or a velocity change instead of a straight position change. And/or put a acceleration/velocity limiter in there too.

Hi there while building the hip file, I implemented this solution

pdbExternalCollisions.thumb.png.7767da51f95d51f8b8fb3cb916b49132.png

This works somewhat, but particles fly everywhere, leak through colliders. When a surface collider is used, they just stick.

The reason I am altering positions instead of velocities is because I am trying to emulate the position based approach here: https://vimeo.com/142534638#t=750s, but for external collisions. If this is a bad approach then I'll look into altering the velocity instead.

 

Thanks

 

pbdCollision.hipnc

Link to comment
Share on other sites

3 hours ago, kleer001 said:

Are you doing this before or after other dynamics calculations?

Might be a one-off error.

This is occurring after the dynamics, I figured it was best to handle collisions last to ensure nothing intersects the next timestep.

I've just found that it may be the case that the gas collision detect dop detects other particles in the same geometry, so I'm currently doing some testing on that

Link to comment
Share on other sites

3 minutes ago, kleer001 said:

Are your computations using acceleration? Are you manually recalculating the constraints after the collision?

So currently, in the simplified scene, I'm grabbing the forces off of the force nodes,

then I'm calculating the acceleration, velocity and position from those forces using:

acceleration= (1 / f@mass) * force * Δt
velocity= velocity0 + acceleration
position= position0 + (Δt * velocity)

after that I'm using the logic in the above diagram to handle the external collisions

Link to comment
Share on other sites

14 hours ago, kleer001 said:

Yea, I'd do the collision as a force/acceleration instead of a positional update. Then maybe take it out the next frame?

 

Also, why? Just to learn? Vellum is awesome.

Ahh ok thanks, I'll look into force calculations, but on the topic of vellum, I've had a look in the solver, and it uses position updates for external collisions too.

They do:

    float C = dot(v@P - v@hitpos, v@hitnml);
    if (C < 0)
        v@P+= -C * v@hitnml;

I'm just off to try that out, dunno why they use the letter C.

Yeah it is for learning. Just got a bit sick of using these solvers as a black box.

Thanks for the help and interest,

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...