# Projected Gauss Seivel Algorithm

## Recommended Posts

I am using PGS to solve the contact force part of my rigid body simulator (2D for now). It seems to be functional but I can only seem to get a few decimals worth of accuracy.  The algorithm will start cycling between different values.  I realize that due to the lack of uniqueness theorem that there are many solutions to the NCP due to the introduction of friction.  I want to find one solution that works and I feel that this cycling reduces accuracy.  I tried subspace minimization but that doesn't seem to fix the problem. Fingers crossed that someone can help me.  Thank You.

##### Share on other sites

Floating point numbers generally wind up as heuristics rather than 100% accurate values e.g. there is no way to store 1/3 etc. There are libraries that allow operating on big numbers with higher accuracy  https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html however there is generally a tradeoff between desired accuracy and performance so most 3d software wont implement it instead they run calculations on the GPU. Most GPUs will use double precision floating point rather than floating point leading to more accurate calculations.

##### Share on other sites

Table:

ps. In simple cases, it may help to change the order of operations in the equation. For example, adding/subtracting 1 to 10^-20 will result in truncated fractions..

##### Share on other sites

Thanks for the responses.  As it turns out, I was incorrectly binding dynamic friction to equal zero if there was enough force to break static friction but still zero tangential velocity.  If instead I just let PGS work its magic, the non-zero friction at each vertex cancels out so that an object at rest will continue at rest.

Unfortunately, I don't know much about parallel processing on the GPU.  But that will probably be my next step after extending to 3D.  I suppose in a multi-player online setting the GPU can perform server-side computations such as if a grenade starts to slide or grow after bouncing a few times?

Thanks again.

##### Share on other sites

• 1 month later...

I successfully implemented GJK.  It is fast, but narrow phase is a bottleneck because i do GJK many times in the binary search.  I read about the EPA, expanding poly tope algorithm.

Question:

EPA returns the point on the CSO closest to the origin.  Does this point correspond to the edge/edge or vertex/face to collide first?

##### Share on other sites

I have another question.  It has to do with the interplay of collision detection and contact force. Is it possible to have GJK ignore collision points that are already in contact?  I want to turn off collisions for these points and let Baumgarte correction prevent interpenetration.

##### Share on other sites

• 3 weeks later...

Update:   I am now using Gilbert Johnson Keerthi with margins and expanding polytope algorithm whenever the depth exceeds the sum of the margins.  No narrow phase, no binary search, much better.  My next question is about an optimization I want to use on the contact force side.   A sphere has only one contact point, but a polytope can have many.  For example, a box stacked on another box has up to eight contact points.  I know how to find location, signed distance, and normal vector.  I want to consolidate these contact points into one contact force.  Is it possible?  Thank you.

##### Share on other sites

Posted (edited)

To check whether two objects of any shape have collided, the programmer can treat them as spheres at the first stage, i.e. calculate the min-max bounding box from all points, calculate the center point and the maximum radius. Then, if the distance between two such spheres is greater than the sum of the radii, the objects are too far away to be bothered with. However, if the distance between them is smaller, a less optimal, slower algorithm is performed to check the objects nearby.

Several levels of spheres are used in 3D games. One sphere to cover the entire body. A second set of smaller spheres for all parts of the body. These are checked similarly to the previous step, but instead of comparing triangles with triangles (or polygons with polygons), because they are very slow for the processor, still spheres vs spheres are checked.

People use KD-Tree (3D), Octree (3D) or Quad-tree (2D) to optimize such work.

i.e. objects that are close to each other are in the same leaf or in a neighboring leaf.

If an object does not move between frames, it does not need to be removed from the leaf and added to a new one.

With a fixed number of elements, you can use voxels ("volumetric pixels").

Remember that in animation up to a certain level, you can reuse calculations from the previous frame(s) in future frames.

Edited by Sensei
##### Share on other sites

Thank you.  More to come.

## Create an account

Register a new account