Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intersections between edge bodies or chain bodies #105

Open
Boyan-In-Christ opened this issue Sep 23, 2019 · 13 comments
Open

Intersections between edge bodies or chain bodies #105

Boyan-In-Christ opened this issue Sep 23, 2019 · 13 comments

Comments

@Boyan-In-Christ
Copy link

Boyan-In-Christ commented Sep 23, 2019

Dear Ali, first thank you for this simple and powerful library you have developed.
I am using it in my research. And I met a problem.
when I try to make packed convex hulls. These hulls I used connected "edge" shape.
The code is like this:

 var convex_edge_i = planck.Edge(planck.Vec2(hull[i].x, hull[i].y), planck.Vec2(hull[i + 1].x, hull[i + 1].y));
var fixture_convex_i = body.createFixture(convex_edge_i, 0);

when I use DistanceJoint to drew these "convex hull" body together, After the simulation, it results these intersections.
The setting of DistanceJoint I used is:

                    let distanceJoint = planck.DistanceJoint({
                        frequencyHz: 0.4, 
                        dampingRatio: 0.001  
                    },

The simulation setting is:

                let timestep = 1.0 / 10.0;
                let velocityIterations = 5;
                let positionIterations = 2;
                // Simulation loop
                // attraction simulation
                for (let i = 0; i < 300; ++i) {
                    // Instruct the world to perform a single step of simulation.
                    // It is generally best to keep the time step and iterations fixed.
                    world.step(timestep, velocityIterations, positionIterations);
                }

When I change this convex hulls into "chain" type, seems the result it the same.
Do you have any idea about this? Do these settings influence the result? How to avoid intersections? Many thanks!!

@Boyan-In-Christ
Copy link
Author

Boyan-In-Christ commented Sep 23, 2019 via email

@shakiba
Copy link
Collaborator

shakiba commented Sep 25, 2019

As far as I know if your container is dynamic this is the common solution:
http://piqnt.com/planck.js/Tumbler

@Boyan-In-Christ
Copy link
Author

Boyan-In-Christ commented Sep 27, 2019

Thank you so much Ali, this helped a lot. it is now much better.
I referenced http://piqnt.com/planck.js/Tumbler also http://piqnt.com/planck.js/Mixer
Both "polygon" or "edge" seems could work as the element of building the bounding box for lots of objects.
I did two implementations.
The first one still have some intersections. The second one seems like what you mentioned before.
One more question: When I use the first implementation how to avoid intersections? Can I set some repelling force on the body, so that when such attachments exist, the body can be separated? Each body can keep some distance from other bodies?
Thank you so much!!

@shakiba
Copy link
Collaborator

shakiba commented Sep 28, 2019

Could you share your testbed on codepen/jsbin?

@Boyan-In-Christ
Copy link
Author

Dear Ali, I made a codepen, here is the link: https://codepen.io/bozheng-stokes/pen/abormNX
There can be intersections somehow. You could also change "box" to "edge", by change
var use_box = true;
var use_edge = false;
to
var use_box = false;
var use_edge = true;

Thank you very much for your advice on this.

@shakiba
Copy link
Collaborator

shakiba commented Sep 28, 2019

Could you try setting walls as bullet?

@shakiba
Copy link
Collaborator

shakiba commented Sep 28, 2019

Bullet didn't fix it, but I was able to fix it with this:

            let distance_joint_setting = {
                frequencyHz: 0.4,
                dampingRatio: 0.01
            };

@shakiba
Copy link
Collaborator

shakiba commented Sep 28, 2019

Great example by the way, thanks for sharing it! I will add it to list of projects made with planck.js, if you don't mind?

@Boyan-In-Christ
Copy link
Author

Boyan-In-Christ commented Sep 29, 2019

Dear Ali, thank you for your time on this. This parameters are very tricky...is there any best practices?
I don't mind you use this code. But I used the code of computing convex Hull from others. Maybe it is better to change it to boxes instead of convex hulls.
If you don't mind, I have one more question from my side. Seems the settings of parameters are quite tricky. If I change the density of the fixture or parameters of the simulation the result can be different. Intersection can still be there.
Can this be solved? Is it because of collision computation? I saw a open source project

https://github.com/Sinova/Collisions/blob/master/README.md#anchor-demos

Can this be integrated into Planck.js?
Thanks again and nice weekend!

@shakiba
Copy link
Collaborator

shakiba commented Sep 29, 2019

Actually my first suggestion (setting bullet: true for walls) was correct. I was setting that for other bodies by mistake. Please ignore my other suggestion.

Just change line 181 to var body = world.createDynamicBody({ bullet: true });.

@shakiba
Copy link
Collaborator

shakiba commented Sep 29, 2019

That's a very interesting open-source project, but I'm just maintaining planck.js right now.

@Boyan-In-Christ
Copy link
Author

Thank you very much Ali. It indeed works. But actually these objects are not at a high speed, why they still can cause intersections? Also the computational cost of setting them to bullets is really high. When I set objects' bullet to true, the computation time seems exponentially increased according to the number of the bullet objects. How is the difficulty of solving this in planck.js?
Many Thanks again!!

@shakiba
Copy link
Collaborator

shakiba commented Sep 30, 2019

You may also be able to fix it by adjusting planck.internal.Settings variables. But I don't know much more.

Also I recommend discussing this with Box2D community as well, Planck.js is based on Box2D.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants