DG_PENETRATION_TOL settable for each shape

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

DG_PENETRATION_TOL settable for each shape

Postby Esharc » Thu Feb 01, 2018 4:00 am

Good morning,

I was wondering if it would be possible to make the DG_PENETRATION_TOL constant a seperate penetration tolerance for each shape that can be set from within our application?

The problem that I am having is that I have a cylinder shape that is standing on a piece of ground that is not perfectly flat. So the cylinder sways from side to side the whole time.

Thanks in advance
Esharc
 
Posts: 120
Joined: Tue Jan 10, 2017 5:23 am
Location: South Africa

Re: DG_PENETRATION_TOL settable for each shape

Postby Julio Jerez » Thu Feb 01, 2018 9:59 am

how the collision penetration will help?
all the penetration does is that removes a 1/1000 of a unit for the skin of the shape.
Thsi is a performance optimization that avoid many trials when calculation the intersection plane of two shape.
this is consider in the closest distance calculation, if not then the calculation of closest point will have many false positives and end up doing expensive false interpenetration
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: DG_PENETRATION_TOL settable for each shape

Postby Esharc » Fri Feb 02, 2018 12:48 am

When I set the tolerance to a bigger value just to test, then the cylinder shape stopped swaying from side to side.

If the shape's collisions penetrate slightly deeper into the other body, then the collision point is moved slightly which allows the shapes to stand still.

Unless there is something else that I am missing?
Esharc
 
Posts: 120
Joined: Tue Jan 10, 2017 5:23 am
Location: South Africa

Re: DG_PENETRATION_TOL settable for each shape

Postby JoeJ » Fri Feb 02, 2018 5:36 am

Esharc wrote:I have a cylinder shape that is standing on a piece of ground that is not perfectly flat.


Does that mean the ground is a spherical shape, like big sphere for planet or so? If so, tesselating it might be the solution, even if it sounds expensive.

(I guess modifying tolerance solves only few cases by luck, but other objects would still sway.)
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: DG_PENETRATION_TOL settable for each shape

Postby Esharc » Fri Feb 02, 2018 9:02 am

It is a simulated mining area.

The terrain is already tessellated. That is where the problem comes it, the shape lies on the are where two shapes from the terrain come together.

I guess I could just move the shape to a flatter part of the terrain. That will solve my problem.
Esharc
 
Posts: 120
Joined: Tue Jan 10, 2017 5:23 am
Location: South Africa

Re: DG_PENETRATION_TOL settable for each shape

Postby Julio Jerez » Fri Feb 02, 2018 9:57 am

Oh you want the constant to be larger than it is now so that the contact point penetrate more?
or you want the other way?
this is hwo the penetration is used by contact calculation
Code: Select all
dgFloat32 penetration = m_normal.DotProduct4(m_closestPoint1 - m_closestPoint0).GetScalar() - m_proxy->m_skinThickness - DG_PENETRATION_TOL;

as you can see the penetration is splited into to two parts, this is new on newton 3.14 before the only value was m_skinThickness, but was too inflexible.
so now the default value that was use is DG_PENETRATION_TOL is 1/1024 which used to be
1/256 approximated one limiter for MKS system and m_skinThisckess is zero.
void NewtonMaterialSetContactThickness (const NewtonMaterial* const materialHandle, dFloat thickness)

This is usually a problem when using very every small shapes where the tolerance become a significant fraction of the size of the shape.
that can be control with thsi function.
void NewtonSetContactMergeTolerance (const NewtonWorld* const newtonWorld, dFloat tolerance)

her are some questions:
I am confused is you problem because the shape is too bug of is too small?
when to change the define did you chnage it is the shape only of to chneg the define.
can you post a picture of the cituation so that I can see what is going on.

one solution that you coudl try is to model that cylsind with a conve hull, that's if the cyludircal shape is no use for some purose, a convex hull will land of a face .
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: DG_PENETRATION_TOL settable for each shape

Postby Esharc » Mon Feb 05, 2018 2:38 am

I originally wanted the constant to be more so that the point can penetrate more, but that was before you showed me the m_skinThickness that I can set.

That is exactly what I was looking for.

I don't think the shape is the actual problem. Our terrain is tesselated. I think the shape lies perfectly in our world on a "fault" line (if I can call it that). That "fault" is not entirely flat, almost like the peak of a mountain.

I changed the actual define to a bigger value. But that caused problems with the other shapes like the wheels of our vehicles. So I changed it back. That is why I was wondering if that could be done per shape. Which it can using the m_skinThickness it would seem.

I have attached an image.
DrumOnTerrain.png


As can be seen in the image, the cylinder lies on the line of the terrain.
Esharc
 
Posts: 120
Joined: Tue Jan 10, 2017 5:23 am
Location: South Africa

Re: DG_PENETRATION_TOL settable for each shape

Postby Julio Jerez » Mon Feb 05, 2018 12:48 pm

The define is not used by all shapes, I think the cylinder and the box are the only one that uses it, but I am not sure.
The defined is used be the contact solver,
The cylinder just happens to use it, and as I explain before the are used for optimizing the calculation.

I see if I can add function to add skin thickness to a shape and will only apply to the shapes that use the second.
I am not sure how it will behave but that should be easy.
Give few hours to do it.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: DG_PENETRATION_TOL settable for each shape

Postby Julio Jerez » Mon Feb 05, 2018 3:55 pm

OK I start adding the feature, I hack the cylinder to see how will work.
This is actually a nice functionality to have by is not as trivial as just shagging the define,
basically what it will do is that is should make the shape inside a little smaller, and you can see that it kind of work. but not quite because the effect should be that the shape should act as if it has some friction, because it lands on some planar face.
so in the case with a shape lands in a place where any infinitesinal motion makes it lose a contact if the contact is on the suface, these will hold the shape.
Instead what happen is that the solve see a smallest shape and the cylinder carcass is only there for showing.
This is because the engine uses the Tolerance only for the support points only, there are other places where this has to be taken into account.

If you sync you will see a demo shows that, the line that hack the sickness is here
file: ..\sdk\dgPhysics\dgCollisionCylinder.cpp
Code: Select all
void dgCollisionCylinder::Init (dgFloat32 radio0, dgFloat32 radio1, dgFloat32 height)
{
m_skinThickness = 0.1f;


you can change that to the value you think will fix the problem and let me know before I move on and make a formal feature, please.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: DG_PENETRATION_TOL settable for each shape

Postby Julio Jerez » Mon Feb 05, 2018 4:35 pm

This request was like me having Dejaboo because I know that functional was there at some point in the pass, and it was
Code: Select all
//NEWTON_API dFloat NewtonCollisionGetSkinThickness (const NewtonCollision* const collision);


but I commented out and eventually removed, the reason was that when I made the collision system instance based, the thickness can't be a feature of the shape it has to be a feature of the instance.
imagine tow cylinders of equal dimensions, if you need one with thickness and the other without, it will be impossible.
So what I have to do is change the support vertex interface to pass the thickness as parameter.

it should be eassy to do, but please let me know if the test worked for you before I go on.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: DG_PENETRATION_TOL settable for each shape

Postby Esharc » Tue Feb 06, 2018 8:28 am

Thank you for adding the feature for me.

Sorry for the delayed reply, but it has been a while since I synced and there were a lot of changes.

The test for the cylinder does solve my problem. It would be great if you could add the feature.
Esharc
 
Posts: 120
Joined: Tue Jan 10, 2017 5:23 am
Location: South Africa

Re: DG_PENETRATION_TOL settable for each shape

Postby Julio Jerez » Tue Feb 06, 2018 10:22 am

ok I added the support
Code: Select all
dFloat NewtonCollisionGetSkinThickness (const NewtonCollision* const collision);
void NewtonCollisionSetSkinThickness(const NewtonCollision* const collision, dFloat thickness);


so far I implement only for the cylinder supportVertex, late I will apply to the shapes wher is apply.

notice that this functionality in fact trim the collision shape. as the thickness is large an large the effect is the shape start to lose all of the shape edges and replace for beveled corners.
this is because now point points can satisfy the condition of support point.
so you should set to the smallest possible value.

so essentially what is does is the is use a smaller shape define by all points in the inside of the shape at distance m_penetration distance. therefore there may be a single closest point for which the intersection plane define 2d shape that can support the collision shape stable.

this provide stability on areas like you showed, at the Spence of less accurate contacts. kind of like the a dented tank.

you should make your cylider large by the skin thickness.

in the demo I first made a skin thickness 0.1 and it looks ridicules, but shows that is really works.
then I set it to 0.01, which is till 100 time bigger that the default value of the define and is near perfect, I support for a relatively large shape.
you should be able to get it with even smaller value, for older version for newton this was 1/256 which I believe is above of 1/8 of an inch more or less, but caused problems for small shapes, so now for 3.14 is 1/1024 and the contact solver uses more robust algorithm to deal with numerical inaccuracies.

anyway, let me know how it goes.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: DG_PENETRATION_TOL settable for each shape

Postby JernejL » Tue Feb 06, 2018 3:01 pm

This sounds cool, so we can just set shape thickness, but how is this different to material thickness?
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: DG_PENETRATION_TOL settable for each shape

Postby Julio Jerez » Tue Feb 06, 2018 4:17 pm

Oh I see how that can be confusing. They are very different things.
To explaing it requires a litle undernation of how the collision works.

The collision system is based on a especial case of a theorem called the Minkowski difference of two polyhedral. https://en.wikipedia.org/wiki/Minkowski_addition

the special case is that the Mink Diff of tow convex polyhedral is another convex polyhedral and this is true in all dimensions. so to explain we use a two d system.

basically to build a naïve the mink different of two polygon you build an array of vector in which for point of polygon A you subtract all vertices of polygon of B.
This generate a vector of point and the convex hull of that new set of point is the Mink difference.

this is very expensive to do taht way, so the are tow algorithm thet came to tyeh resques.
1-The GJK algorithm
2-Quick Hull algorithm,

GJK is much faster but it only functional when the two shape do not overlap each oether.
and here is where it becomes difficult because for collision because a collision system
are interested in intersection of shapes.
Most collision systems are variance of those two algorithm in some for ot another.

So what most people do is the they assume the shapes do not overlap and run GJK, and three things can happens.

a) the shapes do not overlap which is determine if the origin of the Mink diff is outside the shape.
b) the shapes overlap which is determined if the origin of the Mink diff is inside the shape.
c) the shape touch on the surface determined if the origin of the Mink diff is on the surface.

case a and b and clear cut, case c is very hard to resolve because as the shapes get closer and closer
the distance from the origin to the surface become smaller and smaller and numerical errors start to creep in to the point where you can get a collision point that is numerically correct and geometrical incorrect. Unfortunately case C is the most common one for a physic engine.

To go around that problem, most system do not allow for case C to ever happen and as soon and the distance to the surface point falls below some small value, they declare an acceptable collision and use that as collision point. That small distance is what in newton is called the Material Skin thickness. Therefore Material Thickness is the is the distance between two shapes and does not affect the shape themselves.

When the distance happen to be smaller, the algorithm declare penetation and resolve collision
using the quick hull algorithm.

some people like to pretened they invented something, and renamed it expanding polytope because the algorith does a directed guided search to the point close to the surface. but this is just a quick hull with another name.

Quick Hull can be used to resolve collision in all cases because is general and it never ever fail,
however is far more expensive that GHK, and that's what justify using two algorithm instead of just one.

Early versions of newton did not used GJK, instead used Quick Hull for every thing, but after 2.xx I start adding GLK reluctantly, and say reluctantly because GJK is one of those algorithm that are numerically unstable, very prone to give you wrong answer that are numerically valid.

This is why in newton, I still use Material Skin thickness set to zero to force all collision to report penetration and resolve using Quick Hull, GJK only used mostly for sophisticated trivial rejection test. Basically for calculating distance between two pair and decide if they need to calculation contact or not.

The new Parameter works on the shape by making it smaller, but I explained that already.

I hope this is clear.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: DG_PENETRATION_TOL settable for each shape

Postby Esharc » Wed Feb 07, 2018 12:48 am

Thank you.

In my test I ran yesterday, I had the thickness set to 0.005 and it worked. So you are right. A very small number is needed.

I will sync and let you know if I encounter any problems.
Esharc
 
Posts: 120
Joined: Tue Jan 10, 2017 5:23 am
Location: South Africa


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 14 guests

cron