I\'m wanting to create a physics engine within Java. However it\'s not the code I\'m bothered about. It\'s simply the math of rigid body physics, specifically forces and how the
Applied forces do not play a role in the calculation of contact impulses because the impulses are said to occur on a time scale much smaller than the simulation time step. Basically the change is velocity during an impact because of gravity or other forces is negligible.
rotation is form of kinetic energy
first the analogy to movement
alpha
- angular position [rad]omega
- angular speed [rad/s]epsilon
- angular acceleration [rad/s^2]alpha(t)/(dt^2)=omega(t)/dt=epsilon(t)
now the inertia
I
- quadratic rotation mass inertia [kg.m^2]m
- mass [kg]M
- torque [N.m]and some equations to be exploited
M=epsilon*I
- torque needed to achieve acceleration or vice versa [N.m]acc=epsilon*radius
- perimeter acceleration [m/s^2]vel=omega*radius
- perimeter speed [m/s^2]equation #1 can be used to directly compute the force. Equations #2,#3 can be used to calculate friction based forces like wheels grip/drag. Do not forget about the kinetic energy Ek=0.5*m*vel^2+0.5*I*omega^2
so you can exploit the law of preserving energy.
During continuous contact of object1
with object2
in rotation happens this
Perimeter speed/acceleration create interaction force, this is slowing down the rotation of object2
creating drag force on the object2
and reacting force on the object1
.
if object1
is not fixed then this force also create torque and rotates the object1
If the rotation is forced to stop suddenly then all rotational part of kinetic energy is moved to the collision reaction Force impulse.
If object is in more complicated rotation motion then you should compute the actual rotation axis and alpha,omega,epsilon
and use that because object can rotate with more rotations each with different center of rotation.
Also if object is rotating and another rotation is applied in different axis then this creates gyroscopic torque creating also rotation in the third axis perpendicular to both.
So when yo put all these together you have a idea of what structures you need. Sorry can not be more specific than this without further info about the structures and properties of your simulation ...
If I understand correctly, you worry about the different corners of the square - one with an impact, three without.
However, since you want to do rigid body dynamics, it is more helpful to think about the rigid body as having a center of mass (in this case, the square's center), a position, a rotation, and a geometry (in this case the square, but it could be anything).
The corners of the vertices are in constant position and rotation with regards to the center of mass - it's only the rigid body's position and rotation which change all four corners position in the world at once. An advantage of this view is that it is independent of the geometry - you could have 10 or 20 corners, and the approach would be the same.
With regard to computing the rotation: Gravity is working as before. However, you now have another force (from the impulse over the time it acts) - and you have to add the effects of the two in order to get the complete outcome of the system.
The impulse will be due to one of the corners being in collision in the case you describe. It has to be computed at the contact point, with a contact normal - in this case the normal of the flat surface.
If the normal points in a different direction than the center of mass, this will lead to a rotation (as well as a position change).
The amount of the position change is due to how you model the contact computation and resolution, material properties, numerical stepper, impact velocity, time step, ...
As others mentioned, reading up on physics (rigid body dynamics) and physics simulations might be a good starting point to understand the concepts better.