1

I am trying to make a simple 2D physics engine with circles and capsules. So far, I have been able to resolve the velocities of circular bodies after a collision, but I wish to create events like a curve ball or a rolling wheel.

So far, I have a method for calculating the new value for the normal component of each body in a collision, but I am unsure how to calculate the resulting angular and tangential velocities.

Collision resolution (without rotation) $$ \begin{array}{l} v=\ velocity\ of\ Circle\ A\\ u\ =\ velocity\ of\ Circle\ B \end{array}$$

Conservation of Kinetic Energy: $$\frac{1}{2} m_{A} v_{normal\ ( before)}^{2} +\frac{1}{2} m_{B} u_{normal\ ( before)}^{2} =\frac{1}{2} m_{A} v_{normal\ ( after)}^{2} +\frac{1}{2} m_{B} u_{normal\ ( after)}^{2}$$

Conservation of Momentum $$m_{A} v_{normal\ ( before)} +m_{B} u_{normal\ ( before)} =m_{A} v_{normal\ ( after)} +m_{B} u_{normal\ ( after)}$$

Formula for resulting velocities in the RHS: $$ \begin{array}{l} v_{normal\ ( after) \ =\ \frac{v_{normal\ ( before)}( m_{A} -\ m_{B}) +2m_{B} u_{normal\ ( before)}}{m_{A} +\ m_{B}}}\\ u_{normal\ ( after) \ =\ \frac{u_{normal\ ( before)}( m_{B} -\ m_{A}) +2m_{A} v_{normal\ ( before)}}{m_{A} +\ m_{B}}} \end{array}$$

The normal parts are calculated according to the formula above while the tangential part of the velocity is unchanged. This means that the effect of a curve/spin ball cannot be achieved.

This is my take on resolving the tangential component of the bodies' velocities after collision, along with their normal component.

Collision resolution (with rotation)

By definition, $$ \begin{array}{l} v_{angular} =\frac{v_{tangent}}{r}\\ E_{rotational\ KE} =\frac{1}{2} Iv_{angular}^{2}\\ \ \ \ \ \ \ \ \ \ \ \ \ \ =\frac{1}{2}\left(\frac{1}{2} mr^{2}\right)\left(\frac{v_{tangent}}{r}\right)^{2} \tag{rotational inertia of disc}\\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ =\ \frac{1}{4} mv_{tangent}^{2}\\ P_{angular\ momentum} \ =\ I\left(\frac{v_{tangent}}{r}\right)\\ \ \ \ \ \ \ \ \ =\ \frac{1}{2} mrv_{tangent} \end{array}$$

Therefore, Kinetic Energy of Circular body A is: $$\frac{1}{2} m\left( v_{normal}^{2} +\frac{1}{2} v_{tangent}^{2}\right)$$

Conservation of Kinetic Energy: $$ \begin{array}{l} \frac{1}{2} m_{1}\left( v_{normal\ ( before)}^{2} +\frac{1}{2} v_{tangent\ ( before)}^{2}\right) +\frac{1}{2} m_{2}\left( u_{normal\ ( before)}^{2} +\frac{1}{2} u_{tangent\ ( before)}^{2}\right)\\ =\ \frac{1}{2} m_{1}\left( v_{normal\ ( after)}^{2} +\frac{1}{2} v_{tangent\ ( after)}^{2}\right) +\frac{1}{2} m_{2}\left( u_{normal\ ( after)}^{2} +\frac{1}{2} u_{tangent\ ( after)}^{2}\right) \end{array}$$

Conservation of Momentum: $$ \begin{array}{l} m_{1}\left( v_{normal\ ( before)} +\frac{r_{A}}{2} v_{tangent\ ( before)}\right) +m_{2}\left( u_{normal\ ( before)} +\frac{r_{B}}{2} u_{tangent\ ( before)}\right)\\ m_{1}\left( v_{normal\ ( after)} +\frac{r_{A}}{2} v_{tangent\ ( after)}\right) +m_{2}\left( u_{normal\ ( after)} +\frac{r_{B}}{2} u_{tangent\ ( after)}\right) \end{array}$$

There seems to be no way to isolate out the velocities in the RHS of the equations and calculate them individually. I am not sure if this is even the right way, as I am not sure if the two tangential velocities (one is the tangent component of the velocity vector, the other is the angular velocity times its radius) can be resolved together.

It would be helpful to point me towards some resources as what I see online only discuss about the rotations of polygons. Thanks!

Paul
  • 11
  • You will get lost unless use vector notation for developing the equations. Trying to do it by component will result in really complex expressions that are difficult to manipulate and error prone. – John Alexiou Jan 03 '22 at 17:59
  • See https://www.cs.cmu.edu/~baraff/sigcourse/notesd1.pdf and https://www.cs.cmu.edu/~baraff/sigcourse/notesd2.pdf – John Alexiou Jan 03 '22 at 19:44

1 Answers1

1

The following is a common modeling technique when it comes to rigid body dynamics with impacts. The 3D case is just a projection of the 3D case with the simplification that the mass moment of inertia is a scalar value and not a tensor like in 3D. That and all rotations happen perpendicular to the plane.

Consider two bodies in contact, each with its motion described as velocity and rotation at the center of mass. The contact is described by a point A and the contact normal direction $\hat{n}$.

For simplification, the location of each body's center of mass is described relative to A with the vectors $\vec{c}_1$ and $\vec{c}_2$.

$$\begin{aligned}\vec{c}_{1} & =\vec{r}_{1}-\vec{r}_{A} & \vec{c}_{2} & =\vec{r}_{2}-\vec{r}_{A}\end{aligned}$$

fig1

During the impact, a unit of momentum with magnitude $J$ is exchanged between bodies (1) and (2). This is called the impulse. The contact normal is defined such that the impulse adds momentum to body (2) and removes momentum from body (1).

Once the impulse $J$ is known, the change in motion for each body is described by the following equations.

3D $$\begin{aligned} \Delta\vec{v}_{1}&=-\tfrac{J}{m_{1}}\hat{n}&\Delta\vec{v}_{2}&=+\tfrac{J}{m_{2}}\hat{n}\\\Delta\vec{\omega}_{1}&=-I_{1}^{-1}\left(-\vec{c}_{1}\times\hat{n}\right)J&\Delta\vec{\omega}_{2}&=+I_{2}^{-1}\left(-\vec{c}_{2}\times\hat{n}\right)J \end{aligned}$$

2D $$\begin{aligned}\begin{pmatrix}\Delta\dot{x}_{1}\\ \Delta\dot{y}_{1} \end{pmatrix}&=-\tfrac{1}{m_{1}}\begin{pmatrix}n_{x}\\ n_{y} \end{pmatrix}J&\begin{pmatrix}\Delta\dot{x}_{2}\\ \Delta\dot{y}_{2} \end{pmatrix}&=+\tfrac{1}{m_{2}}\begin{pmatrix}n_{x}\\ n_{y} \end{pmatrix}J\\\Delta{\omega}_{1}&=\tfrac{n_{y}cx_{1}-n_{x}cy_{1}}{I_{1}}J&\Delta{\omega}_{2}&=\tfrac{n_{y}cx_{2}-n_{x}cy_{2}}{I_{2}}J \end{aligned}$$

where $m_1$ and $m_2$ are the body mass values, and $I_1$ and $I_2$ are the body mass moment of inertia about the center of mass.

So to find the impulse amount, first find the relative velocity of the two bodies along the contact normal (call the impact speed)

3D $$v_{{\rm imp}}=\hat{n}\cdot\left(\vec{v}_{1}+\vec{c}_{1}\times\vec{\omega}_{1}-\vec{v}_{2}-\vec{c}_{2}\times\vec{\omega}_{2}\right)$$

2D $$v_{{\rm imp}}=n_{x}\left(\dot{x}_{1}+cy_{1}\omega_{1}-\dot{x}_{2}-cy_{2}\omega_{2}\right)+n_{y}\left(\dot{y}_{1}-cx_{1}\omega_{1}-\dot{y}_{2}+cx_{2}\omega_{2}\right)$$

Then calculate the reduced mass of the system along the contact normal

3D $$m_{\rm reduced} = \left[\tfrac{1}{m_{1}}+\tfrac{1}{m_{2}}+\left(\hat{n}\times\vec{c}_{1}\right)\cdot I_{1}^{-1}\left(\hat{n}\times\vec{c}_{1}\right)+\left(\hat{n}\times\vec{c}_{2}\right)\cdot I_{2}^{-1}\left(\hat{n}\times\vec{c}_{2}\right)\right]^{-1}$$ 2D $$ m_{\rm reduced} = \left[ \tfrac{1}{m_{1}}+\tfrac{1}{m_{2}}+\tfrac{\left(n_{y}cx_{1}-n_{x}cy_{1}\right)^{2}}{I_{1}}+\tfrac{\left(n_{y}cx_{2}-n_{x}cy_{2}\right)^{2}}{I_{2}} \right]^{-1} $$

And, finally use the coefficient of restitution $\epsilon$ to find the impulse

$$ J = (1+\epsilon)\,m_{\rm reduced}\,v_{\rm imp} $$

It is really that simple.

John Alexiou
  • 38,341