• Advertisement
Sign in to follow this  

Constraint-based physics in 2D?

This topic is 1094 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

 

I've been doing some research into constraint-based physics and am hitting some walls, specifically for 2D systems.

 

I've always been fascinated by box2D and physics in games in general. I know that constraints is my next step, but I just can't grasp the whole topic. It's especially more difficult because a lot of articles are written for 3D.

 

I'll post some of the articles I've been reading:

 

http://gamedevelopment.tutsplus.com/tutorials/simulate-tearable-cloth-and-ragdolls-with-simple-verlet-integration--gamedev-519

 

http://www.wildbunny.co.uk/blog/2011/04/06/physics-engines-for-dummies/

 

[This article has been very interesting, but I feel it lacks in explaining some things, such as the reflection vector, also I didn't understand what the values in this piece of code is supposed to represent (the author only mentions normal, and distance from origin:

Planes[4] =
{
   (1,  0, 1),
   (0, -1, 1),
   (-1, 0, 1),
   (0,  1, 1)
} 

]

 

 

 http://allenchou.net/game-physics-series/

 

[I haven't gone too deep into his writing as it's 3D and i'm specifically looking to get going in 2D].

 

 

 

 

Do you have any other documents going into constraints? I'd like something from a less detailed perspective and more focused on explaining the math and algorithms. I'm having quite a bit of trouble getting into the maths as I feel it's not well enough explained from the start. I'm also unsure of where constraints might be used and where the different types of constraints come in.

 

Thank you.

Share this post


Link to post
Share on other sites
Advertisement

First: thumbs up for asking "How can I learn?" rather than "Where can I find code for this?" What a pleasant change. cool.png

 

 

 


I feel it lacks in explaining some things, such as the reflection vector, also I didn't understand what the values in this piece of code is supposed to represent (the author only mentions normal, and distance from origin:

 

Yeah, a lot of books/articles regarding collision detection and resolution make assumptions about the depth of a reader's familiarity** with physics, vectors, analytical geometry and calculus. It's likely that reflection vector is the physics principle of "the angle of reflection equals the angle of incidence," or more simply Vreflect = -Vincidence (V bolded indicating a vector). (EDIT: Sorry, I got too enthusiastic with my simplification.) The piece of code you posted likely indicates the coefficients of the plane equation for the plane in question. I.e., ax + by +cz + d = 0. If you're not familiar with terms used, you can google for the bolded phrases.

 

** If you don't have a working familiarity with those subjects, you might want to start by brushing up on them. Google is your friend and wikipedia is a good place for short articles.

 

 

 


I'd like something from a less detailed perspective and more focused on explaining the math and algorithms.

 

If you're interested in a more complete approach to constraints, it may, in my opinion, be difficult to find something better than Chou's article. His description of constraints is brief and exact:

 

Constraints

 

The resolution phase of a constraints-based physics engine uses the concept of constraints. A free rigid body in 3D has 6 degrees of freedom: 3 positional and 3 rotational; a rigid body in 2D has 3 degrees of freedom: 2 positional and 1 rotational. A constraint decreases the degrees of freedom of a rigid body. For instance, a constraint that pins an object in space at its center of mass decreases the object’s degrees of freedom by 3: all the positional degrees of freedom are removed and the object can thus now only rotate with 3 degrees of freedom.

 

===============

 

That is, his "constraints" are one approach to modeling simulations, and are an application of math based on physics.

 

That article, in my opinion, does focus on the math and algorithms. He's very careful to define and explain the terms he uses - for readers that understand calculus or physics. I.e., the process of constraint resolution uses tools ( general principles of math and physics), none of which are unique in themselves with regard to collision detection and resolution.

 

Depending on how simple or complex you want to model constraints, with regard to 2D vs 3D, 2D is nothing more than 3D with the constraints that there is no linear displacement, velocity or acceleration in the 3rd dimension. IMHO, rotation is more easily applied in 2D by assuming a third axis. I.e., for an object spinning in the X-Y plane, assuming the angular velocity/acceleration is described by a vector along the Z axis simplifies things with regard to vector math. As you mention, you can find lots of resources regarding 3D approaches, and they can be applied directly to your situation.

 

You don't mention your level of education or experience with physics and math, and I'm in no way trying to insult or belittle you. Consider, however, that any article or book must assume some level of knowledge on the reader's part. Without knowing what you do and don't understand, it's difficult to recommend anything better than Chou. It's obvious you can and have learn(ed) based on your own research. You've likely found that there are few resources (I know of none) detailing 2D constraints of more than "do this with X, do this with Y," and which teach you the basics of the math involved. Continue teaching yourself about the math and physics principles [divorced from the topic of constraints!] needed to build a constraint method such as Chou presents.

 

And, certainly, specific questions about particular terms and their meaning (just as you posted above), will normally get good responses here on gamedev.

Edited by Buckeye

Share this post


Link to post
Share on other sites

Start by reading Erin Catto's online resources (besides Box2D), like his papers and presentations. Understanding what constraints are doing is a math problem, not so much a computer science problem.

 

The overall idea is to form a system of linear equations and solve them with a simple iterative Gauss-Seidel solver.

 

WildBunny's constraints, along with that verlet paper aren't going to help you.

 

I personally don't like that Allen Chou link since the information is very high level, and you can just read Erin's direct resources instead.

 

Edit: Oh and one more thing, since you're pondering specifically about that reflection vector/matrix you should probably pick up the book Essential Mathematics by Jim Van Verth -- you'll want a very solid understanding of the fundamentals (linear algebra, numeric robustness) if you want to really understand this kind of stuff.

Edited by Randy Gaul

Share this post


Link to post
Share on other sites

First: thumbs up for asking "How can I learn?" rather than "Where can I find code for this?" What a pleasant change. cool.png

 

 

 


I feel it lacks in explaining some things, such as the reflection vector, also I didn't understand what the values in this piece of code is supposed to represent (the author only mentions normal, and distance from origin:

 

Yeah, a lot of books/articles regarding collision detection and resolution make assumptions about the depth of a reader's familiarity** with physics, vectors, analytical geometry and calculus. It's likely that reflection vector is the physics principle of "the angle of reflection equals the angle of incidence," or more simply Vreflect = -Vincidence (V bolded indicating a vector). (EDIT: Sorry, I got too enthusiastic with my simplification.) The piece of code you posted likely indicates the coefficients of the plane equation for the plane in question. I.e., ax + by +cz + d = 0. If you're not familiar with terms used, you can google for the bolded phrases.

 

** If you don't have a working familiarity with those subjects, you might want to start by brushing up on them. Google is your friend and wikipedia is a good place for short articles.

 

 

 


I'd like something from a less detailed perspective and more focused on explaining the math and algorithms.

 

If you're interested in a more complete approach to constraints, it may, in my opinion, be difficult to find something better than Chou's article. His description of constraints is brief and exact:

 

Constraints

 

The resolution phase of a constraints-based physics engine uses the concept of constraints. A free rigid body in 3D has 6 degrees of freedom: 3 positional and 3 rotational; a rigid body in 2D has 3 degrees of freedom: 2 positional and 1 rotational. A constraint decreases the degrees of freedom of a rigid body. For instance, a constraint that pins an object in space at its center of mass decreases the object’s degrees of freedom by 3: all the positional degrees of freedom are removed and the object can thus now only rotate with 3 degrees of freedom.

 

===============

 

That is, his "constraints" are one approach to modeling simulations, and are an application of math based on physics.

 

That article, in my opinion, does focus on the math and algorithms. He's very careful to define and explain the terms he uses - for readers that understand calculus or physics. I.e., the process of constraint resolution uses tools ( general principles of math and physics), none of which are unique in themselves with regard to collision detection and resolution.

 

Depending on how simple or complex you want to model constraints, with regard to 2D vs 3D, 2D is nothing more than 3D with the constraints that there is no linear displacement, velocity or acceleration in the 3rd dimension. IMHO, rotation is more easily applied in 2D by assuming a third axis. I.e., for an object spinning in the X-Y plane, assuming the angular velocity/acceleration is described by a vector along the Z axis simplifies things with regard to vector math. As you mention, you can find lots of resources regarding 3D approaches, and they can be applied directly to your situation.

 

You don't mention your level of education or experience with physics and math, and I'm in no way trying to insult or belittle you. Consider, however, that any article or book must assume some level of knowledge on the reader's part. Without knowing what you do and don't understand, it's difficult to recommend anything better than Chou. It's obvious you can and have learn(ed) based on your own research. You've likely found that there are few resources (I know of none) detailing 2D constraints of more than "do this with X, do this with Y," and which teach you the basics of the math involved. Continue teaching yourself about the math and physics principles [divorced from the topic of constraints!] needed to build a constraint method such as Chou presents.

 

And, certainly, specific questions about particular terms and their meaning (just as you posted above), will normally get good responses here on gamedev.

 

 

Thank you, I always try to understand how and why things work the way they do smile.png

 

I have a pretty decent understanding of physics and math. I specifically focus on calculus and linear algebra [moderate here, I'm still finding going through khan videos on this topic] and whatever else I feel I can handle at the time. I have good knowledge of analytical geometry which I use quite comfortably. 

 

I'm currently reading up on the bolded sections, thank you for that, this will definitely help. It's difficult to google when you don't know the correct terminology.

 

I'll have to read up on Chou's work, I'll just have to bite the bullet and hope what I read helps me in my future work! I discredited it far too quickly. 

 

I understand what you mean, and is why I specifically focus on 2D. I like to tackle everything I do from bottom to top. 2D is far easier to understand and model, IMO. I'll just need to be much more attentive and start converting from 3D to 2D. 

 

No worries, should have posted my level up-top. I'm self-taught on most things mathematics and physics. I posted a little higher in this reply as to what I know smile.png I'll continue reading up on resources.

 

Thanks, i'm trying to be as specific as possible! Especially to do with terminology which I can't always google.

 

Thank you for the reply and your helpful knowledge! The terminology will help me out a lot! 

 

 

Start by reading Erin Catto's online resources (besides Box2D), like his papers and presentations. Understanding what constraints are doing is a math problem, not so much a computer science problem.

 

The overall idea is to form a system of linear equations and solve them with a simple iterative Gauss-Seidel solver.

 

WildBunny's constraints, along with that verlet paper aren't going to help you.

 

I personally don't like that Allen Chou link since the information is very high level, and you can just read Erin's direct resources instead.

 

Edit: Oh and one more thing, since you're pondering specifically about that reflection vector/matrix you should probably pick up the book Essential Mathematics by Jim Van Verth -- you'll want a very solid understanding of the fundamentals (linear algebra, numeric robustness) if you want to really understand this kind of stuff.

 

I would more than anything love to read Erin's papers, I just can't seem to find the appropriate content online. I tried going through all of his slides (from last year all the way back to his first) but all it did what whet my appetite. That's what I actually lead me to this point!

 

Would it be too much to ask for a few google links to find some of his papers smile.png? (edit: I'd like to note that I have and am currently searching for these papers, I would prefer to read everything he's written!)

 

I was hoping that wasn't the case, but that's why I posted it here. Along with Chou's link; I too feel like it's far too high level. Erin's resources would be a gem to get my hands on.

 

Thank you, I'll definitely grab the book. I have a pretty reasonable understanding on linear algebra, but i'm always up to read maths books! (edit #II: Wow, this book is really really good, thank you for the recommendation!)

Edited by uberNooble

Share this post


Link to post
Share on other sites

Awesome, I didn't know box2D Lite was so open, using the standard lib will definitely be a big help too! I'm checking out everything on that list.

 

I appreciate your help! If you know of any other pieces of literature I could be reading up on, (articles or books), let me know :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement