<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://pybullet.org/Bullet/phpBB3/app.php/feed/topic/8681" />

	<title>Real-Time Physics Simulation Forum</title>
	
	<link href="https://pybullet.org/Bullet/phpBB3/index.php" />
	<updated>2012-12-18T23:43:24+00:00</updated>

	<author><name><![CDATA[Real-Time Physics Simulation Forum]]></name></author>
	<id>https://pybullet.org/Bullet/phpBB3/app.php/feed/topic/8681</id>

		<entry>
		<author><name><![CDATA[c0der]]></name></author>
		<updated>2012-12-18T23:43:24+00:00</updated>

		<published>2012-12-18T23:43:24+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=29512#p29512</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=29512#p29512"/>
		<title type="html"><![CDATA[Re: Distance constraint]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=29512#p29512"><![CDATA[
Never mind, was a stupid mistake not to use two anchors. Works perfect now with drift correction.<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=9431">c0der</a> — Tue Dec 18, 2012 11:43 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[c0der]]></name></author>
		<updated>2012-12-17T23:02:53+00:00</updated>

		<published>2012-12-17T23:02:53+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=29510#p29510</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=29510#p29510"/>
		<title type="html"><![CDATA[Distance constraint]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=29510#p29510"><![CDATA[
Hi,<br><br>I have coded the following distance constraint but am having problems with the bias, since the relative position can sometimes be zero, here is the code, please help !<br><br>I have tested it without the bias and it still behaves like a point-to-point constraint<br><br>Thanks<br><div class="codebox"><p>Code: </p><pre><code>AMG3DDistanceJoint::AMG3DDistanceJoint(AMG3DRigidBody *pRigidBody1, AMG3DRigidBody *pRigidBody2, AMG3DVector4 vAnchorPoint){m_pRigidBody1= pRigidBody1;m_pRigidBody2= pRigidBody2;AMG3DMatrix4x4 Rot1, Rot1T, Rot2, Rot2T;AMG3DQuaternion q1 = m_pRigidBody1-&gt;quatOrientation;AMG3DQuaternion q2 = m_pRigidBody2-&gt;quatOrientation;q1.toMatrix(&amp;Rot1);Rot1T.transposeOf(Rot1);q2.toMatrix(&amp;Rot2);Rot2T.transposeOf(Rot2);localAnchor1 =  Rot1T*(vAnchorPoint - m_pRigidBody1-&gt;position);localAnchor2 =  Rot2T*(vAnchorPoint - m_pRigidBody2-&gt;position);initialDistance = (localAnchor1-localAnchor2).magnitude();}void AMG3DDistanceJoint::preStep(AMG3DScalar dt){if(dt&lt;=0.0f)return;AMG3DScalar k_biasFactor = (AMG3DPhysicsWorld::g_AMG3D_PositionCorrection) ? 0.2f : 0.0f;AMG3DMatrix4x4 Rot1, Rot2;AMG3DQuaternion q1 = m_pRigidBody1-&gt;quatOrientation;AMG3DQuaternion q2 = m_pRigidBody2-&gt;quatOrientation;q1.toMatrix(&amp;Rot1);q2.toMatrix(&amp;Rot2);AMG3DVector4 ra = Rot1*localAnchor1;AMG3DVector4 rb = Rot2*localAnchor2;AMG3DMatrix3x3 I;I.identity();// Compute the bias factor to prevent driftAMG3DVector4 dp = m_pRigidBody1-&gt;position + ra - m_pRigidBody2-&gt;position - rb; // Relative positionAMG3DScalar C = dp.magnitude() - initialDistance;bias = k_biasFactor / dt * C;dp.normalize();n = dp; // n = dp/|dp|InvMa = I*m_pRigidBody1-&gt;invMass; // Ma^-1SkewRa = ra.skew(); // [~ra]AMG3DMatrix3x3 InvIa = m_pRigidBody1-&gt;invIWorld; // Ia^-1SkewRaT.transposeOf(SkewRa); // [~ra]TInvMb = I*m_pRigidBody2-&gt;invMass; // Mb^-1SkewRb = rb.skew(); // [~rb]AMG3DMatrix3x3 InvIb = m_pRigidBody2-&gt;invIWorld; // Ib^-1SkewRbT.transposeOf(SkewRb); // [~rb]T// a = JM^-1JT// a = n.(Ma^-1*n + [~ra]T*Ia^-1*n*[~ra] + Mb^-1*n + [~rb]T*Ib^-1*n*[~rb])a = n.dot(InvMa*n + SkewRaT*InvIa*n*SkewRa + InvMb*n + SkewRbT*InvIb*n*SkewRb);}void AMG3DDistanceJoint::applyImpulse(){AMG3DVector4 va = m_pRigidBody1-&gt;velocity;AMG3DVector4 wa = m_pRigidBody1-&gt;angularVelocity;AMG3DVector4 vb = m_pRigidBody2-&gt;velocity;AMG3DVector4 wb = m_pRigidBody2-&gt;angularVelocity;// b = -Jvi - beta/h*CAMG3DScalar b = n.reverseOf().dot(va + SkewRaT*wa - vb - SkewRbT*wb) - bias;// x = lambda (corrective impulse)lambda = a&gt;0 ? b/a : 0;P += lambda; // Accumulate impulse for warm starting (To Do: Add warm starting)// vfa = via + Ma^-1*n*1*lambda// wfa = wia + Ia^-1-n*[~ra]*lambda// vfb = vib + Mb^-1*n*-1*lambda// wfb = wib + Ib^-1*n*-[~rb]*lambdam_pRigidBody1-&gt;velocity+= InvMa*n*lambda;m_pRigidBody1-&gt;angularVelocity+= m_pRigidBody1-&gt;invIWorld*n*SkewRa*lambda;m_pRigidBody2-&gt;velocity-= InvMb*n*lambda;m_pRigidBody2-&gt;angularVelocity-= m_pRigidBody2-&gt;invIWorld*n*SkewRb*lambda;}</code></pre></div><p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=9431">c0der</a> — Mon Dec 17, 2012 11:02 pm</p><hr />
]]></content>
	</entry>
	</feed>
