Ball and socket joint

Please don't post Bullet support questions here, use the above forums instead.
Lukas Korba
Posts: 4
Joined: Wed Nov 28, 2007 1:54 pm

Ball and socket joint

Post by Lukas Korba »

Hi.. I need help.. I have to implement 3d ball and socket joint into my diploma thesis and I dont understand them. Do you anybody some articles, informations or pieces code to help me with it? Thank you everyone... please Im novice in constraint problematic, so be symphatetic
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: Ball and socket joint

Post by Dirk Gregorius »

In what context do you have to implement them? Can you give some more information?
Lukas Korba
Posts: 4
Joined: Wed Nov 28, 2007 1:54 pm

Re: Ball and socket joint

Post by Lukas Korba »

I implement whole physics engine.. I have rigids, world and CD complete.. and I want add joints to engine... for firts - ball and socket joint.. And I have no idea how to do this
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: Ball and socket joint

Post by Dirk Gregorius »

Are you already solving contacts? Do you understand that constraints are usually formulated as algebraic equations along with the equations of motion (Newton-Euler)? Do you understand that this build a system of differential algebraic equations? Are you aware that game physic engines usually use iterative methods to solve constrained dynamic systems, e.g. sequential impulses or PGS? Are you familar with these methods or have you at least heard about it? Or do you plan to use direct methods like maybe Dantzig or Lemke? For constraints you can use reduced coordinates (e.g. Featherstone) or Lagrange multipliers - do you understand the difference and do you know what you want to use?

You *must* ask more specific. I can't answer such a generic question like: "I need to write a physic engine - tell me how this works" :-)
bone
Posts: 231
Joined: Tue Feb 20, 2007 4:56 pm

Re: Ball and socket joint

Post by bone »

Short answer: you need to calculate and then apply a force that holds the ball-and-socket together.

Longer answer:

You have two bodies, each with an offset to the joint location. Modern game physics engines usually try to keep the relative velocity of these two body offsets at zero (another style is to keep the relative *acceleration* at zero). In other words, after you've gathered and applied all external forces and torques and take into account the velocity and rotation of the two bodies, the relative velocity of those two body offsets will typically not be zero, meaning that one is moving in a different direction than the other. You need to calculate the force or impulse that restores their relative velocity to zero, so they don't come apart. Then of course you'll find that integration is not perfect and they eventually drift apart anyway, at which point you'll need to apply some sort of stabilization technique.

Anyway, what you really want to do is look at some papers, like Erin Catto's Iterative Dynamics, which you can do a search for.
Lukas Korba
Posts: 4
Joined: Wed Nov 28, 2007 1:54 pm

Re: Ball and socket joint

Post by Lukas Korba »

to Dirk Gregorius: let me explain my situation... Im programmer which primary uses physics engines.. but for diploma thesis I want implement a small own physics engine. For now I have complete rigid body, their collision shape OBB, test for intersection and generate contacts.. Simulation world too.. rigid bodies are complete.. But I havent contact solver yet and joints, because I havent enough theory in my head. So Im looking for some help to make next step. I find some articles, but didnt work. Your questions are very new for me, so answer is I dont understand most of your questions. I dont know who or what is "Dantzig or Lemke" or "(e.g. Featherstone) or Lagrange multipliers"... Im sorry.. Im just looking for easy way to do my last steps..

to bone: to Dirk Gregorius too: BUT I understand teory how this it work.. I need find vector of impulse... becasuse.. first step is create joint...............and last step is applyImpulse... but what is between them I havent idea... I have Implement whole structure for ball and socket joint.. Rest is one method "BallJoint::Update(dt)"... The same is for contact solver.. I understand theory, because I have contact points(include normal and penetration) and last step is applyImpulse which mean reaction on contact... but I dont know how compute impulse for this... I saw some articles of course, but not enough for me.. thank you for help to me... Have a nice day professionals
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: Ball and socket joint

Post by Dirk Gregorius »

I recommend looking at Erin Catto's presentations here: http://www.gphysics.com/downloads. Look at the GDC2006 and 2007 presentations and also make yourself familiar with the Box2D_Lite code. I think a good goal for your thesis is to port the code to 3D. So once you understand this I recommend you come back with specific questions and we get it working together.

Here is the short idea (skipping unimportant details):

Constraints impose restrictions on the relative position and velocity of the bodies. E.g. when you have a contact point you don't want any penetration at the contact point. In order to have no penetration you are *not* allowed to have a relative approaching velocity at the contac points. For the ball socket joint you want a point a1 on one shape be coincident with a point a2 on the other shape. Again this imposes also a velocity restriction on the system. The relative velocity at the anchor point must be zero, otherwise the anchor points would obviously drift apart.

The overall algorithm goes like this:

1) You integrate the body velocities forward in time
2) You sweep over all constraints and apply impulses such that your velocity restrictions will become satisfied. E.g. you relative velocity becomes zero
3) Since satisfying one constraint might break another one you do this in several iterations. This is called relaxation.
4) Once your velocities satisfy the velocity restrictions you integrate the positions using this "corrected" velocities.

The iterative relaxation loop is basically computing the constraint forces. Basically you remove all invalid velocities that would have normally been taken care of the constraint forces.

HTH,
-Dirk


PS:
I also recommend the following thesis do get a little bit more backgorund:

http://www.win.tue.nl/dynamo/publicatio ... thesis.pdf
ftp://ftp.diku.dk/diku/image/publicatio ... 050401.pdf
Lukas Korba
Posts: 4
Joined: Wed Nov 28, 2007 1:54 pm

Re: Ball and socket joint

Post by Lukas Korba »

Thank you very much.. for first I read all this articles and then try some implement.. You are really good man!