What exactly are "Islands" in Newton?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

What exactly are "Islands" in Newton?

Postby oliver » Thu Sep 29, 2016 7:12 am

Hello,

what exactly constitutes and "island" in Newton?

I would like to (ab)use Newton to give me all bodies that are somehow
interacting (eg touching or linked via constraints). This seems to be
relatively easy with the help of the islandUpdateEvent, but the results differ
depending on whether the collision shape is wrapped in a compound shape or not.

For example, in a simulation with N identical bodies that touch each other,
the following setup results in a single island with N bodies:
Code: Select all
NewtonCollision *box = NewtonCreateBox(world, 1, 1, 1, 0, NULL);
NewtonBody *body = NewtonCreateDynamicBody(world, box, TM);


whereas the same with a compound shape results in N islands, with a single body in each:
Code: Select all
 NewtonCollision *box = NewtonCreateBox(world, 1, 1, 1, 0, NULL);
 compound = NewtonCreateCompoundCollision(world, 0);
 NewtonCompoundCollisionAddSubCollision(cshape, box);
 NewtonBody *body = NewtonCreateDynamicBody(world, compound, TM);


Am I doing something wrong with the compound shapes, or are "islands" something
different altogether?
oliver
 
Posts: 36
Joined: Sat Sep 17, 2016 10:31 am

Re: What exactly are "Islands" in Newton?

Postby Julio Jerez » Thu Sep 29, 2016 6:42 pm

Island was a feature I added for some one long time ago for newton 1.5x.
basically is a call back for deciding of a ground of bodies on the screen can be skipped.

if you want to have the island you would have to build the yourself either at the beginning or after the frame update or using a lister.

There are few algorithm that can be use for that, depth first search, breath first search or, disjoint-set, or any other. My favorite is https://en.wikipedia.org/wiki/Disjoint- ... _structure
because it run on linear time for all intended and propose with a very small inner loop.

Newton provide this interface.

Code: Select all
NewtonBody* NewtonWorldGetFirstBody (const NewtonWorld* const newtonWorld);
NewtonBody* NewtonWorldGetNextBody (const NewtonWorld* const newtonWorld, const NewtonBody* const curBody);

NewtonJoint* NewtonBodyGetFirstJoint (const NewtonBody* const body);
NewtonJoint* NewtonBodyGetNextJoint (const NewtonBody* const body, const NewtonJoint* const joint);
NewtonJoint* NewtonBodyGetFirstContactJoint (const NewtonBody* const body);
NewtonJoint* NewtonBodyGetNextContactJoint (const NewtonBody* const body, const NewtonJoint* const contactJoint);

if you want I can add a utility function that that you can use to build the islands, this weekend.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: What exactly are "Islands" in Newton?

Postby oliver » Fri Sep 30, 2016 6:36 am

Thank you for the disjoint sets algorithm - I did not know that one.

if you want I can add a utility function that that you can use to build the islands, this weekend.


This is very kind of you, but I would rather you enjoy your weekend :) Besides, does Newton not have this information readily available somewhere? Isn't this directly the narrowphase output?

I have not had time to try out your functions yet, but could you explain how they would allow me to build the connected sets? I thought getFirstBody and getNextBody would simply allow me to iterate over all bodies in the world. Do I have this wrong?
oliver
 
Posts: 36
Joined: Sat Sep 17, 2016 10:31 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 22 guests