How to create a distance constraint?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: How to create a distance constraint?

Postby Julio Jerez » Fri Feb 14, 2014 12:14 am

Oh I undestand now, Joe is right it onlt the one dof.

However that make unstanble because by trying to inforce only the distance there side velocity can become very large for the
joint to is one step. It may need the calculation of the giorosccopy effect to make up for the side veliocity.

make the video to see how it looks.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: How to create a distance constraint?

Postby JoeJ » Fri Feb 14, 2014 2:11 am

Code: Select all
p0 -= dir * distance * 0.5;
      p1 += dir * distance * 0.5;
      
      sQuat rot;
      rot.FromVecToVec (m_js.XAxis(), dir);      
      m_js = rot * m_js;
      m_js.Normalize ();
      matrix0.Rotation()->FromQuat (m_js);

      NewtonUserJointAddLinearRow (joint, (float*)&p0, (float*)&p1, (float*)&matrix0[0]);
      NewtonUserJointAddLinearRow (joint, (float*)&p0, (float*)&p1, (float*)&matrix0[1]);
      NewtonUserJointAddLinearRow (joint, (float*)&p0, (float*)&p1, (float*)&matrix0[2]);


To add the stabilizing side rows we could use Gramm Schmidt or store a quat and adjust it to distance direction by axis / angle rotation from old to new directon. This avoids the bad discontinuous changes from Gramm Schmidt. Tested and works very good :)
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: How to create a distance constraint?

Postby jamesm6162 » Tue Oct 27, 2015 8:44 am

Hi
Apologies for reviving this thread. I am stuck with the exact same problem now.

JoeJ wrote:
Code: Select all
p0 -= dir * distance * 0.5;
      p1 += dir * distance * 0.5;
      
      sQuat rot;
      rot.FromVecToVec (m_js.XAxis(), dir);      
      m_js = rot * m_js;
      m_js.Normalize ();
      matrix0.Rotation()->FromQuat (m_js);

      NewtonUserJointAddLinearRow (joint, (float*)&p0, (float*)&p1, (float*)&matrix0[0]);
      NewtonUserJointAddLinearRow (joint, (float*)&p0, (float*)&p1, (float*)&matrix0[1]);
      NewtonUserJointAddLinearRow (joint, (float*)&p0, (float*)&p1, (float*)&matrix0[2]);


To add the stabilizing side rows we could use Gramm Schmidt or store a quat and adjust it to distance direction by axis / angle rotation from old to new directon. This avoids the bad discontinuous changes from Gramm Schmidt. Tested and works very good :)


Could you please explain how you store the m_js quaternion for this distance constraint?
jamesm6162
 
Posts: 49
Joined: Wed Aug 12, 2015 8:50 am

Re: How to create a distance constraint?

Postby JoeJ » Tue Oct 27, 2015 11:21 am

the quaternion m_js must be available from the joint callback, so i store it in the class of my joint, like other joint data (distance value in this case).
Does that answer the question?

It might be worth to add a direction check to minimize rotation, while still keeping final orientation aligned to error direction:

Code: Select all
sQuat rot;
if (m_js.XAxis().Dot(dir)) > 0
      rot.FromVecToVec (m_js.XAxis(), dir);
else   
       rot.FromVecToVec (m_js.XAxis(), -dir);


Usually i also use this quat relative to one of the joint bodies to make it completely independent from worldspace.

The advantage from this over simpler gramm schmidt is small but it's there :)
Distance joints work best if they are as close to the bodys COM as possible.
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: How to create a distance constraint?

Postby jamesm6162 » Wed Oct 28, 2015 3:35 am

Hi

Thanks I got it working now.

Regards

James
jamesm6162
 
Posts: 49
Joined: Wed Aug 12, 2015 8:50 am

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron