2

I'm trying to implement my own physics for an app I'm making in C++, OpenframeWorks. I'm currently using Box2D but I don't need collision detection so I want something much lighter.

I have a world with gravity and a dynamic object with movement constrained by a prismatic joint of an arbitrary length at an arbitrary angle, attached to a static object. Friction is simulated using the joint motor.

I've looked at

Resources for 2d game physics

But everything here seems to focus on building complete physics engines which I don't need to do. Could anyone point me in the right direction for the maths on this?

Community
  • 1
  • 1
Simon Katan
  • 706
  • 7
  • 11

2 Answers2

0

You just need to separate the force of gravity into two components; Along the Prismatic Joint Axis, and anything else. (See Free body diagrams)

This is easily achieved with the vector dot product between the gravity vector and axis vector. If you first scale the axis vector to length 1, the result of the dot product will be the force along the axis.

To translate the force into acceleration, you just need to divide by the mass of the moving object.

Markus Jarderot
  • 86,735
  • 21
  • 136
  • 138
  • The problem is more complex than that. You have three equations of motion that you need to solve simultaneous: x-, y, and rotation about z. What about rotary inertia? You didn't say anything that's incorrect, but it either means you have a shallow, incomplete understanding of the problem or felt limited in the time, space, and effort you were willing to use. – duffymo May 28 '12 at 18:45
  • I decided to take Duffymo's advice though I did read this first which took me some of the way towards understanding the problem http://www.scribd.com/doc/28815747/Classic-Physics-Ramp. – Simon Katan May 30 '12 at 13:41
0

If Box2D has what you want, I'd recommend you reconsider your "lighter" requirement. Unless you can quantify the harm caused by using a library with a few more bytes, I'd say that the benefit will outweigh the cost of you writing it for yourself.

If you have a good understanding of the physics, and want to learn how to do it, by all means go ahead. If not, use what someone more knowledgeable than you has provided and forget the size of the library.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • I need 1000s of particles. When I use Box2D, the collision detection slows down my program. As Box2D offers collision filtering but not turning off collision detection all together, I would in this case be better off implementing my own physics without collision detection which over 1000s of particles would be much lighter – Simon Katan May 29 '12 at 21:08
  • I doubt that you'll be better off. If you have to ask here how to do it, I'd say you aren't up to the task. – duffymo May 29 '12 at 21:39
  • Duffymo I've taken your word for it and found a solution using Box2d. Since there's no obvious way to disable the collision detection, I simply instantiated a new world for every group of joined objects. This allows me around 2250 objects instead of 300. – Simon Katan May 30 '12 at 13:36