my question is still pending. I mean, I understand that to build a hinge you need to lock the 2 others axis with 2 newtonuserjointaddangularrow constraints. Is that true ?
There are two methods for doing constraint dynamics.
Generalized coordinates, and reduced coordinated.
In general there are few generalized coodinate methods:
Lagragian, virtual displacement, A very popular special case of lagragian is the Featherstone.
But these methds are quite hard to implement as a tool building blocks objects. The reason is that they do not play well with under and over determined systems, this is called holonomizity. Which basically means, the number of degree of freedom most be equal to the number of geometrical constraint.
These methods are also preferred by software packages that do symbolic dynamic. They can generate differential equation from energy function and geometrical constraints.
This method also deal with non lineal constraint better.
At the high level, you can think of these method as a top down tree, where each node has one parent, and each child can only move on the local scapce of it parent.
So the math is derived on a subset of degree of freedom.
This lend to a recursive evaluation of the system.
The problem with these system is that ther are very limited, the moment a body interact with anything that constitute a loop in the tree, and the recursion is not longer possible.
The second method is reduced condinates.
This is the method that comes out straight of newton equation of motion.
The movement of all bodies is on the same space, inertial or non inertial.
Each body is described by six dof, and can only change its state of motion by a Generalized force.
This is the method taught in most of high school and under graduate classes in college, and is its not until you take graduate classes on mechanic that you learn Generalized systems.
In reduced system, you apply a force to change the motion, you can consider that preventing a relative motion is a change of motion.
So what you do is that you add a constraint forces to all the dof you want to freeze, and let the one you want the motion free or partially free.
So a hinge will add 3 linear constraint to prevent realative motion, and two angular constraint to prevent rotation around any axis perpendicular to the ping.
Since you can described any ping perpendicular to the hinge axis with two mutualy perpendicular unit ping, you only need two constraints.
So yes, a free hinge will has 5 degrees of restricted degrees of freedoms in a reduced system. As opposed to a hinge is say virtual force that can specify with 1 dof.
Following the 6 x 1 and 6 x 6 vector and matrix notation.
functions newtonuserjointaddangularrow and newtonuserjointaddlinearrow
are the implementation of the vector components of equation
J * invM ×Jt = c
that form part of a larger sparce matrix for the entire system of interconnected bodies.
The functions populates C, J, Jt. alone with some precomputed values based on the joint type. for example, say you want to define a hinge.
A hinge is defined by one free degree of freedom, using reduced coordinate system.
it means we restrict 5 degrees of freedom and leave one free, we can also allow for the six dof to have some control kind of motion.
in code this translate to 5 or 6 constraint equation into the general force equation
and here is where the 6 x 1 notation help because we can say that a for pair is a vector of 6 x 1 dimension where three are force and three are torque. so instead of calling it torque we call it F
that is F = text + g0 * J0 + g1 * J1 + g2 * J2 + + g3 * J3 + g4 * J4
if we derive this, We will quickly realize that there is a pattern to do this that generalize for any arbitrary arrangement of rigid body contrarians.
for a hinge:
three rows are three non colinear points to enforce zero relative acceleration and velocity and two mutually perpendicular angular axis to the desired ping of rotation to enforce zero relative angular acceleration and angular drift.
optionally it can emit the six dof in the case the hinge is something like an actuator or whatever angular behavior you want.
once all those vectors are set, the rest in the linear algebraic solution of that larger sparce matrix.
In the larger sparse matrix, in which each joint is a block diagonal with two off diagonals off block matrices.