Grasshopper

algorithmic modeling for Rhino

Hi,

Is it possible to have particle sphere collision without adding the Sphere Collision goal?

If, not how to add this goal properly as explained below?

It is associated with issue of winding 2 long springs (picture, movie attached):

I add particles and springs inside C# component, where KangarooSolver is also implemented.

When I try to add sphere collision goal I get into trouble:

    // SphereCollide SC = new SphereCollide(PS.GetPositions().ToList(), 0.01, 1);
    //GoalList.Add(SC);

Because particles are added incrementally, so I need to check new List of points every frame.

Kind Regards,

Petras

Views: 1003

Attachments:

Replies to This Discussion

Hi Petras

I would approach this by creating only one SphereCollide goal and add it to the GoalList at the beginning. Then at every update iteration. I update its PIndices array of that goal by appending the indices of the to new particles.

I did not have time to check the code myself. Please let me know if it works or not :)

// Declare the SphereCollide and SphereCollidePIndices in the Custom Additional Code session 

SphereCollide SC = null;

List<int> SphereCollideIndices = null;

...

if (Reset)

{

   ...

   // Here we just input a empty list of Point3d in to the SphereCollide constructor, ...

   // ... because later we will define and update the PIndices of SphereCollide manually,

   // ... and the SphereCollide goal will get the current particle positions it needs for calculation

   // ... based on these PIndices

   SC = new SphereCollide(new List<Point3d>(), 0.01, 1);

   GoalList.Add(SC);

   SphereCollidePIndices = new List<int>();

   ...

}

...

// Add two new particles

PS.AddParticle(b0.loc, 0.001);
PS.AddParticle(b1.loc, 0.001);

// Append the two new indices to the SphereCollidePIndices list

SphereCollidePIndices.Add(PS.ParticleCount - 1);

SphereCollidePIndices.Add(PS.ParticleCount - 2);

// And update the PIndices of the SphereCollide goal

SC.PIndices = SphereCollidePIndices.ToArray();

// (no need to re-add SC to GoalList because it has already been added at the beginning)

Hi,

Thank you for a reply, but I already getting an error after this:

      SC = new SphereCollide(new List<Point3d>(),0.01, 1);
      GoalList.Add(SC);

It seems that I cannot add the goal with empty list of points:

error: One or more errors occurred. (line: 0)

Do you know a solution for it?

Thanks,

Petras

Hi Petras

I am back at my computer now so I play with the code a bit. 

The empty point list was not the problem actually. It was because I missed a few things:

1. After constructing the SphereCollide object I also need to manually initialize its PIndex array

2. When extending the PIndex array to include 2 new particles at every iteration, I also need to extend its Weighting and Move arrays manually as well.

After adding these the codes run without error. But the behavior is not what you expect. probably you can try playing with the spring rest length, sphere radius and perhaps adding some gravity.

The tricky thing with this kind of string simulation is that if you use sphere as colliding geometry, it is a bit tricky to get the radius right. Too small radius can lead to two strings that pass through each other completely without colliding.

GH file attached :) Good luck

Attachments:

Dear Long Nguyen,

Thank you very much :)

There are some new things for me.  Especially indexing, SC.Diam, move and weighting arrays.

My intention was to have a collision radius of half spring, so particles would not go through. But I know that there is a possibility to make a line-line collision custom goal. At this point I would like to work with this method.

Thank you,

Petras

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service