<?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/12769" />

	<title>Real-Time Physics Simulation Forum</title>
	
	<link href="https://pybullet.org/Bullet/phpBB3/index.php" />
	<updated>2021-11-04T11:31:15+00:00</updated>

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

		<entry>
		<author><name><![CDATA[Forinti]]></name></author>
		<updated>2021-11-04T11:31:15+00:00</updated>

		<published>2021-11-04T11:31:15+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43683#p43683</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43683#p43683"/>
		<title type="html"><![CDATA[Re: Boucing with sequential impulse]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43683#p43683"><![CDATA[
I could post my code but it's big and it's been a while since I worked on it, I did a lot of tests and I don't know what state it is anymore, it might be dirty. This is why I am afraid that there will be errors if it is the case it would be a bad support of comprehension for you. I'm currently rewriting my entire game engine and I'm not into the physics part yet.<br><br>If you are new to this field you should try to understand the basics of a physics engine, using circles with one point of contact, without other features (warmstarting, friction, restitution, etc.) and add the features little by little.<br>There are a lot of resources around the internet, I can direct you if you want.<br><br>But what is the goal for you? Because if it's to make a game you should use an existing engine, otherwise you have to be very passionate about the technical part, that's my case and I don't have any qualifications to answer your question.<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=13415">Forinti</a> — Thu Nov 04, 2021 11:31 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[carlstensfer102]]></name></author>
		<updated>2021-11-04T10:36:51+00:00</updated>

		<published>2021-11-04T10:36:51+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43681#p43681</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43681#p43681"/>
		<title type="html"><![CDATA[Re: Boucing with sequential impulse]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43681#p43681"><![CDATA[
And you can post your version of the solution, I would like to understand in detail how to do it right. You also wrote that it took you a long time. How much time and what level of qualification do you have, because I am new to this field, I want to understand which way to expect.<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=14142">carlstensfer102</a> — Thu Nov 04, 2021 10:36 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Forinti]]></name></author>
		<updated>2020-07-16T10:21:29+00:00</updated>

		<published>2020-07-16T10:21:29+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43037#p43037</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43037#p43037"/>
		<title type="html"><![CDATA[Re: Boucing with sequential impulse]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=43037#p43037"><![CDATA[
Hello phenom<br>Did you find a solution ?<br>If this is not resolved can you detail your problem a bit and post your code so that I can help you.<br><br>It will be difficult to detail how I did it because I moved away from the box2d-lite pattern (even if the idea remains the same) because I had precisely this problem of bouncing, and I did not look for the cause in details because it had already taken me a long time.<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=13415">Forinti</a> — Thu Jul 16, 2020 10:21 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[phenom]]></name></author>
		<updated>2020-06-19T04:08:25+00:00</updated>

		<published>2020-06-19T04:08:25+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42936#p42936</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42936#p42936"/>
		<title type="html"><![CDATA[Re: Boucing with sequential impulse]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42936#p42936"><![CDATA[
hello Forinti <br>I have the same issue in bouncing, and I also take the pattern of box2d-lite.<br>Can you tell me in detail how you solved this problem?<br>Thank you！<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=13676">phenom</a> — Fri Jun 19, 2020 4:08 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Forinti]]></name></author>
		<updated>2019-11-23T09:15:24+00:00</updated>

		<published>2019-11-23T09:15:24+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42494#p42494</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42494#p42494"/>
		<title type="html"><![CDATA[Re: Boucing with sequential impulse]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42494#p42494"><![CDATA[
Well, I finally found the solution.<br><br>I decided to solve the problem in the other direction, I took the source code of a functional engine (dyn4j because quite simple and especially in Java)<br>and I reduced it to the minimum possible by incorporating my code (it was quite long).<br><br>I arrived at a point totally identical to my engine with one exception, I explain:<br><br>In my engine I generate and store collision information and constraints in a single object -&gt; Manifold.<br>Then I test his correspondence between the frames and I update his contacts, this take the pattern of box2d-lite.<br><br>In dyn4j, as often in physical engines, this is separated into two distinct entities:<br>The "Manifold" that stores collision information.<br>The "ContactConstraints" that manages the contact constraints.<br><br>This is the only difference between the modified source code and my base code, so I decided to do the same and it works!<br><br>So my problem was simply in the simultaneous update of the information of collisions and constraints,<br>I know that it should work and that there is an error in my code because it is the implementation of box2d-lite.<br><br>But sincerely I spent too much time on it and I will not look where exactly the problem was.<br>And it allowed me to understand the pattern and implementation with constraints that is widespread and more flexible in my opinion.<br><br>Thanks for reading me.<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=13415">Forinti</a> — Sat Nov 23, 2019 9:15 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Forinti]]></name></author>
		<updated>2019-11-10T10:01:44+00:00</updated>

		<published>2019-11-10T10:01:44+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42461#p42461</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42461#p42461"/>
		<title type="html"><![CDATA[Re: Boucing with sequential impulse]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42461#p42461"><![CDATA[
It bothers me a lot but I give up the warmstarting, I can not find the problem and I do tests that make no sense.<br>I'm posting the light engine code or doing tests in case something gets in your way ...<br>Anyway thanks for your help Irlan.<br><div class="codebox"><p>Code: </p><pre><code>package physic;public class Manifold {public static final class Pair {public final Circle circleA;public final Circle circleB;public Pair(Circle circleA, Circle circleB) {this.circleA = circleA;this.circleB = circleB;}@Overridepublic int hashCode() {final int prime = 31;int result = 1;result = prime * result + circleA.id;result = prime * result + circleB.id;return result;}@Overridepublic boolean equals(Object obj) {if (this == obj)return true;if (obj == null)return false;if (getClass() != obj.getClass())return false;Pair other = (Pair) obj;if ((circleA.id == other.circleA.id) &amp;&amp; (circleB.id == other.circleB.id))return true;return false;}}public Circle circleA;public Circle circleB;public Contact contact = new Contact();public Manifold(Pair pair) {this.circleA = pair.circleA;this.circleB = pair.circleB;}public boolean collide() {Circle a = circleA;Circle b = circleB;Vec2 relPos = b.position.sub(a.position);double distSqr = relPos.lenSqr();double radiusSum = a.radius + b.radius;if (distSqr &gt; (radiusSum * radiusSum))return false;double distance = Math.sqrt(distSqr);if (distance == 0d) {contact.normal.set(1d, 0d);contact.position.set(a.position);} else {contact.normal.set(relPos).sclLocal(1d / distance);contact.position.set(contact.normal).sclLocal(a.radius).addLocal(a.position);}return true;}public void updateContact(Contact newContact) {if (Settings.warmstarting) {Vec2 relPos = newContact.position.sub(contact.position);if (relPos.len() &lt;= Settings.contactMatchingDistance) {newContact.accImpulses = contact.accImpulses;}}contact = newContact;}private double getRelativeVelocityAlongNormal() {return circleB.velocity.sub(circleA.velocity).dot(contact.normal);}public void preStep() {contact.normalMass = circleA.invMass + circleB.invMass;contact.normalMass = contact.normalMass &gt; 0d ? 1d / contact.normalMass : 0d;double resting = (Settings.frequency * Settings.gravity) + Settings.epsilon;double rvn = getRelativeVelocityAlongNormal();contact.velocityBias = rvn &lt; -resting ? -Settings.restitution * rvn : 0d;warmStart();}private void warmStart() {Vec2 J = new Vec2();J.x = contact.normal.x * contact.accImpulses;J.y = contact.normal.y * contact.accImpulses;circleA.velocity.x -= J.x * circleA.invMass;circleA.velocity.y -= J.y * circleA.invMass;circleB.velocity.x += J.x * circleB.invMass;circleB.velocity.y += J.y * circleB.invMass;}public void applyImpulses() {double j = contact.normalMass * (-getRelativeVelocityAlongNormal() + contact.velocityBias);double pn0 = contact.accImpulses;contact.accImpulses = Math.max(pn0 + j, 0d);j = contact.accImpulses - pn0;Vec2 jn = contact.normal.scl(j);circleA.velocity.x -= jn.x * circleA.invMass;circleA.velocity.y -= jn.y * circleA.invMass;circleB.velocity.x += jn.x * circleB.invMass;circleB.velocity.y += jn.y * circleB.invMass;}}</code></pre></div><div class="codebox"><p>Code: </p><pre><code>package physic;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import physic.Manifold.Pair;public class World {public final List&lt;Circle&gt; circles = new ArrayList&lt;&gt;();public final Map&lt;Pair, Manifold&gt; contacts = new HashMap&lt;&gt;();public Circle addCircle(double radius, double x, double y, boolean isStatic) {Circle c = new Circle(radius, x, y, isStatic);circles.add(c);return c;}public void update() {broadphase();integrateGravity();preStep();for (int i = 0; i &lt; Settings.solverIterations; i++)applyImpulses();integrateVelocities();}private void broadphase() {for (int i = 0; i &lt; circles.size(); i++) {for (int j = i + 1; j &lt; circles.size(); j++) {Circle circleA = circles.get(i);Circle circleB = circles.get(j);if (circleA.invMass == 0f &amp;&amp; circleB.invMass == 0f)continue;Pair pair = new Pair(circleA, circleB);Manifold newManifold = new Manifold(pair);if (newManifold.collide()) {if (contacts.containsKey(pair)) {contacts.get(pair).updateContact(newManifold.contact);} else {contacts.put(pair, newManifold);}} else {contacts.remove(pair);}}}}private void integrateGravity() {for (Circle c : circles) {if (c.invMass == 0f)continue;c.velocity.y += Settings.frequency * Settings.gravity;}}private void preStep() {for (Manifold m : contacts.values())m.preStep();}private void applyImpulses() {for (Manifold m : contacts.values())m.applyImpulses();}private void integrateVelocities() {for (Circle c : circles) {if (c.invMass == 0f)continue;c.position.x += Settings.frequency * c.velocity.x;c.position.y += Settings.frequency * c.velocity.y;}}}</code></pre></div><p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=13415">Forinti</a> — Sun Nov 10, 2019 10:01 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[irlanrobson]]></name></author>
		<updated>2019-11-07T14:07:34+00:00</updated>

		<published>2019-11-07T14:07:34+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42456#p42456</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42456#p42456"/>
		<title type="html"><![CDATA[Re: Boucing with sequential impulse]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42456#p42456"><![CDATA[
Without warm-starting the solver can take lots of iterations to converge. For this reason you should consider using warm-starting. <br><br>FYI one of the main reasons for a simulation to blow up is a bad choice of integrator. Semi-impicit Euler is stable for non-stiff equations. If your simulation is exploding and it is using this type of integrator there is probably an error hidden somewhere in your code. I would not call a bug an instability problem.<br><blockquote class="uncited"><div>Is it possible to have a stable stack with elastic bodies and warmstarting without adding another feature to the engine?</div></blockquote>Yes, a vertical stack of spheres with varying restitution should be stable and come to rest. I have no problems at this configuration.<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=11211">irlanrobson</a> — Thu Nov 07, 2019 2:07 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Forinti]]></name></author>
		<updated>2019-11-06T19:35:44+00:00</updated>

		<published>2019-11-06T19:35:44+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42452#p42452</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42452#p42452"/>
		<title type="html"><![CDATA[Re: Boucing with sequential impulse]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42452#p42452"><![CDATA[
It's interesting, I'll look at this more deeply.<br>I had just left a little aside the problem described in this post to implement the friction.<br><br>For the bouncing problem, from the last answer I made an extremely lightweight physics engine that only handles circles and resolves only the linear velocity constraint.<br>And I have exactly the same problem. (I can post the code if needed)<br>The simplest solution for me would be to no longer use the warmstarting, but I really do not want to remove this feature ...<br><br>I want to clarify that it is only with stacking, a body falling only on the floor poses no problem in any case.<br>Without warmstarting everything is good, with or without restitution.<br>With warmstarting it is extremely stable without restitution but very unstable with the restitution (even explode).<br><br>I come to doubt that my code has errors and asks me this very simple question:<br>Is it possible to have a stable stack with elastic bodies and warmstarting without adding another feature to the engine?<br><br>thank you in advance<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=13415">Forinti</a> — Wed Nov 06, 2019 7:35 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[irlanrobson]]></name></author>
		<updated>2019-11-04T16:02:18+00:00</updated>

		<published>2019-11-04T16:02:18+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42449#p42449</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42449#p42449"/>
		<title type="html"><![CDATA[Re: Boucing with sequential impulse]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42449#p42449"><![CDATA[
Well, one problem in the code you posted is that it solves the tangent and normal constraints independently. I don't think this is correct. <br><br>The friction forces depend on the normal forces. Therefore, you should solve a tangent constraint followed by a normal constraint or vice-versa since constraint order is important. Recall constraints solved by last are prioritized.<br><br>However, I believe you can find many resources in the literature dealing with decoupled friction.<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=11211">irlanrobson</a> — Mon Nov 04, 2019 4:02 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Forinti]]></name></author>
		<updated>2019-11-03T07:56:44+00:00</updated>

		<published>2019-11-03T07:56:44+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42446#p42446</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42446#p42446"/>
		<title type="html"><![CDATA[Re: Boucing with sequential impulse]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=42446#p42446"><![CDATA[
Hello Irlan,<br><br>I just saw your answer, thank you.<br>I can not stop comparing but something must escape me.<br><br>I will rewrite a test engine that only manages circles with the minimum possible to facilitate debugging and get to the point.<br>In the meantime I'm attaching a video of the problem, if anyone has an idea ...<br><br>Note : in the video I forgot to translate this [Sans warmstarting = Without warmstarting] and [Avec warmstarting = With warmstarting].<br><br><a href="https://www.youtube.com/watch?v=dgSTr9z4Omc" class="postlink">https://www.youtube.com/watch?v=dgSTr9z4Omc</a><p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=13415">Forinti</a> — Sun Nov 03, 2019 7:56 am</p><hr />
]]></content>
	</entry>
	</feed>
