applyed edits from Prof. Carzaniga

This commit is contained in:
Karma Riuk 2023-08-02 12:08:41 +02:00
parent b44c6e5fb0
commit 567ac11dc6
2 changed files with 61 additions and 46 deletions

View File

@ -67,25 +67,25 @@
} }
} }
\abstract { \abstract {Physics engines are a fun and interesting way to learn
Physics engines are a fun and interesting way to learn about a lot of about a the laws of physics, as well as computer science. They
different subjects. First the theoretical concepts, such as the equations provide a real-time simulation of common physical phenomena, and
that dictate the motion of the objects, together with their components, need therefore illustrate theoretical concepts such as the equations that
to be thoroughly understood. Then there is the necessity of finding a way to dictate the motion of objects, The goal of this project was to
represent all of those concepts in a given programming language and to extend an existing physics engine built for demonstration purposes.
make them as efficient as possible so that the simulation runs fluidly. This engine was initially designed and developed to simulate
The task to be completed here was to extend an already existing circular objects (``balls'') in 2D. With this project, we intended
physics engine that only made circles bounce off each other. The extension to extend this engine to also simulate arbitrary polygons, again in
was focused on having the ability to generate some arbitrary polygons and a physically accurate way. The main technical challenges of the
make them bounce off each other in a physically accurate way. The main project is therefore the correct simulation of the dynamics of
issues that rose up during the development of the extension: determining the rigid, polygonal objects. In particular, we developed a model of
inertia of a arbitrary polygon, which is important for realistic polygonal rigid objects; we implemented a simulation of their
impacts; having an accurate collision detection system, which allows the inertial motion, possibly in the presence of a constant force field
engine to know when to make two polygons bounce off each other. Once those such as gravity; we detect collisions between objects; we compute
aspects were worked on and polished, the rest of the implementation went and then simulate the dynamic effects of collisions. The
smoothly. simulations are animated and displayed in real-time. It is also
therefore crucial that the simulation code be efficient to obtain
} smooth animations.}
\counterwithin{figure}{section} \counterwithin{figure}{section}
\counterwithin{equation}{section} \counterwithin{equation}{section}

View File

@ -1,46 +1,61 @@
\section{Theoretical Background} \section{Theoretical Background}
\label{sec:theory} \label{sec:theory}
The theoretical background is everything related to the physics part of the The theoretical background is everything related to the physics part of the
project. It covers the calculating the inertia of different types of polygons; project. It covers the calculation of the inertia of different types of polygons;
different algorithms to detect whether there is a collision between two different algorithms to detect whether there is a collision between
polygons; the resolution of the collision, i.e. finding the final any two polygons; and the resolution of the collision, that is, finding the final
velocity vectors and angular speed of those polygons. velocity vectors and angular speed of those polygons.
\subsection{Moment of inertia} \subsection{Moment of Inertia}
\label{sub:moment} \label{sub:moment}
The inertia of an object refers to the tendency of an object to resist a change The inertia of an object refers to the tendency of an object to resist
of its state of motion or rest, it describes how the object behaves when forces a change of its state of motion or rest, it describes how the object
are applied to it. An object with a lot of inertia requires more force to change behaves when forces are applied to it. In particular, the mass of a
its motion, either to make it move if it's at rest or to stop it if it's already point object (inertial mass) determines the inertia of that objects.
moving. On the other hand, an object with less inertia is easier to set in Thus an object with a large mass requires more force to change its
motion or bring to a halt. motion, either to make it move from an initial state at rest or to
stop it if it is already moving. On the other hand, an object with a
smaller mass is easier to set in motion or to bring to a halt.
The moment of inertia is similar but is used in a slightly different context, it For objects that are not point-like, the motion includes a rotational
specifically refers to the rotational inertia of an object. It measures an component.
object's resistance to changes in its rotational motion and how its mass is
distributed with respect to is axis of rotation.
In the case of this project the axis of rotation is the one along the $z$-axis The moment of inertia is analogous to the mass in determining the
(perpendicular to the plane of the simulation) and placed at the barycenter of inertia of an object with respect to its rotational motion. In other
the polygon. words, the moment of inertia determines the rotational inertia of an
object, that is, the object's resistance to changes in its rotational
motion. The moment of inertia of an object is therefore computed with
respect to a rotation axis, and it is determined by the way the mass
of the object is distributed with respect to the chosen axis of
rotation.
The general formula for the moment of inertia is
For the purpose of this project, we are interested in a 2D simulation.
This means that the axis of rotation is always parallel to the
$z$-axis, perpendicular to the plane of the simulation. Furthermore,
we model the motion of an object using the barycenter of an object as
its reference point. We therefore compute the moment of inertia of a
polygon with respect to a rotation axis that is perpendicular to the
2D plane and that goes through the center of mass of the polygon.
In general, the moment of inertia about a rotation axis $Z$ of a point
mass $m$ at distance $r$ from $Z$ is $I_m=mr^2$. Therefore, for a
generic 2D object $Q$, we integrate over the whole 2D object:
\begin{equation} \begin{equation}
\label{eq:moment_general} \label{eq:moment_general}
I_Q = \int \vec r^2 \rho(\vec r) \diff \mathcal{A} I_Q = \int_{\mathcal{A}}\|\vec r\|^2 \rho(\vec r) \diff \mathcal{A}
\end{equation} \end{equation}
where $\rho$ is the density of object $Q$ in the point $\vec r$ across the where $\rho$ is the density of object $Q$ (mass per unit area) in the
small pieces of area $\mathcal A$ of the object. point $\vec r$ from the across the small pieces of area $\mathcal A$
of the object.
In our case, since we are implementing a 2D engine we can use the $\mathbb{R}^2$ In our case, we use 2D Cartesian coordinates centered in the point
coordinate systems, thus the formula becomes (axis) about which we compute he moment of inertia. Furthermore, we
$$ I_Q = \iint \rho(x, y) \vec r^2 \diff x\diff y$$ consider polygons of uniform density. We can therefore compute:
and since the requirements express that the mass of the polygons is spread
uniformly across its surface, the formula finally becomes
\begin{equation} \begin{equation}
\label{eq:moment} \label{eq:moment}
I_Q = \rho \iint x^2 + y^2 \diff x\diff y I_Q = \rho \iint(x^2 + y^2)\diff x\diff y
\end{equation} \end{equation}
The bounds of the integral depend on the shape of the polygon. In the following The bounds of the integral depend on the shape of the polygon. In the following