stevenxiao / box2d

Automatically exported from code.google.com/p/box2d
0 stars 0 forks source link

A weld joint used to attach two bodies with fixed rotation has no effect #328

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Take any 2 bodies with zero inverse moment of inertias (m_invI == 0.0) - most 
obviously bodies with the fixed rotation flag set to true, but also bodies with 
no fixtures (not sure if that is legal or not...) or bodies with fixtures or 
zero mass. Connect the 2 bodies with a weld joint. Their motion will not be 
constrained by the joint at all; the two bodies will move independently of each 
other.

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?

version 2.2.1, Windows 7, compiled with Visual Studio 2012

Please provide any additional information below.

I've fixed the bug in our version of the code, although I don't know if this is 
the best fix. The problem is in b2WeldJoint::SolvePositionConstraints(), 
specifically with:

b2Vec3 impulse = -K.Solve33(C);
The problem is that with iA and iB both zero in that function, the matrix K is 
zero in the final row and column. The solving method relies on finding the 
determinant; in this case the determinant is zero and so no solution exists.

But, actually we can solve for the x and y components of impulse correctly if 
we use solve22 and just set impulse.z = 0 (which since are dealing with objects 
of fixed rotation or 0  inverse moment of inertia is entirely reasonable). So 
my simple fix was to change the conditional

if (m_frequencyHz > 0.0f)

at line 251 in b2WeldJoint.cpp to

if ((m_frequencyHz > 0.0f) || ((iA + iB) == 0.0f))

This then only uses the positional constraint and correctly calculates the 
impulse to constrain the bodies. There may however be a more aesthetically 
pleasing way to solve the problem.

Original issue reported on code.google.com by Phill.Sk...@gmail.com on 31 Jan 2014 at 9:57

GoogleCodeExporter commented 9 years ago
Completed: At revision: 306  

Fix for issue 328. Added code to handle the degenerate situation of two rigid 
bodies with fixed rotation being connected by a weld joint. This makes the code 
slower for all cases.

Original comment by erinca...@gmail.com on 5 Apr 2014 at 6:53