# Torque Generation

I have written a basic physics engine. It is able to handle rotations. But how do I handle case like this where an object sits on top of another and needs to rotate due to the effect of gravity ? I know that when the center of mass is outside the body will fall down. But I am unable to express this in algorithm. I could make it work for a regular convex polygon (by finding if center of mass is outside of the contact surface). But how do I make it work for irregular convex polygon?

Basically, I need a clear idea of what kinds of forces are acting on the top body so that I am able to make it fall down due to gravity.

• Whenever you exert a force also exert a torque at the intersection point. T=Fxd where d is distance from the center of mass to the point. There is no torque from gravity. – Andrew Wilson Mar 26 '18 at 20:39
• So, what are the intersection points? Since the top object is parallel to the botttom one, I see a line segment. So, what will be the force and the application points? – uttamkhanal Mar 27 '18 at 0:36
• Physically correct would be to say a torque is acting at every point along the line segment between 1 and 2. We can approximate it by using the midpoint of the two contacts. Though it will very very quickly become contact 1 as the upper rect starts to rotate. – Andrew Wilson Mar 27 '18 at 1:04
• As for the force, you should be using some numerical integration to apply forces and torques like Euler or Verlet integration. So given the forces of the two bodies, their collision normals, and mass we can calculate the resulting force. For example, say the bottom rect was unmoveable (infinite mass). Then all the force going into it would be reflected for it to come to rest. In this case the force going into it is Fg. So -Fg is exerted on the upper body at the contact. This is an edge case. But often the case in a platformer like game. Then Torque = cross(Force, dist from CoM) – Andrew Wilson Mar 27 '18 at 1:06