From edccfff766dca8fa9fa6b3e50cd6a4316ddfa324 Mon Sep 17 00:00:00 2001 From: BurntWaffleCake Date: Sat, 30 Dec 2023 11:38:19 -0600 Subject: [PATCH] removed redundant file --- projects/Physics/BallCollision/index.html | 93 ++++++++++++++----- .../BallCollisionOptimization/article.txt | 2 - projects/Physics/BoxCollision/AABBCollision | 1 - 3 files changed, 68 insertions(+), 28 deletions(-) delete mode 100644 projects/Physics/BallCollisionOptimization/article.txt delete mode 160000 projects/Physics/BoxCollision/AABBCollision diff --git a/projects/Physics/BallCollision/index.html b/projects/Physics/BallCollision/index.html index 92c6bfd..032fbde 100644 --- a/projects/Physics/BallCollision/index.html +++ b/projects/Physics/BallCollision/index.html @@ -9,13 +9,16 @@ - + - +
@@ -49,18 +55,26 @@

Ball Collision

What is Ball Collision?

- Ball Collision (or in this case circle collision as we are going to mostly be in 2d), is a way of detecting the overlap or collision of two ball objects. This can very simply be done using - certain properties that each ball holds along with relational data between said balls. + Ball Collision (or in this case circle collision as we are going to mostly be in 2d), is a + way of detecting the overlap or collision of two ball objects. This can very simply be + done using certain properties that each ball holds along with relational data between said + balls.

Point In Circle Algorithm

- From this point forward we will reference balls as circles however the mathematics can be applied to higher dimensions such as with spheres. We can define a circle as an enclosed geometry - which has an infinite number of definable points each a distance of its radius from its center. As such, we can know that a point lies inside of a circle if its distance from the center of - said circle is less than the radius and on the surface of the circle if the distance is equal to the circle's radius. + From this point forward we will reference balls as circles however the mathematics can be + applied to higher dimensions such as with spheres. We can define a circle as an enclosed + geometry which has an infinite number of definable points each a distance of its radius + from its center. As such, we can know that a point lies inside of a circle if its distance + from the center of said circle is less than the radius and on the surface of the circle if + the distance is equal to the circle's radius.

-

\( \vec{d} = \begin{vmatrix} x_{circle} - x_{point} \\ y_{circle} - y_{point} \end{vmatrix} \)

+

+ \( \vec{d} = \begin{vmatrix} x_{circle} - x_{point} \\ y_{circle} - y_{point} + \end{vmatrix} \)
+

\( |\vec{d}| = \sqrt{ {\vec{d}_x}^2 + {\vec{d}_y}^2 } \)

\( l_{distance} = |\vec{d}| \)

Point is in circle when: \( l_{distance} < r_{radius}\)

@@ -71,9 +85,13 @@

Point In Circle Algorithm

Circle To Circle Collision Detection Algorithm

- We now know that a point is in a circle if the distance between the point and the center of the circle is less than the circle's radius. Using this relationship and the fact that all points - on a circle is exactly the distance of the circle's radius from its center, we can deduce that the if the distance between the two circles is less than sum of two circle's radii, they are - colliding. We can in turn calculate the overlap or "depth" of the collision by subtracting the distance from the sum of radii giving us the overlap magnitude. + We now know that a point is in a circle if the distance between the point and the center + of the circle is less than the circle's radius. Using this relationship and the fact that + all points on a circle is exactly the distance of the circle's radius from its center, we + can deduce that the if the distance between the two circles is less than sum of two + circle's radii, they are colliding. We can in turn calculate the overlap or "depth" of the + collision by subtracting the distance from the sum of radii giving us the overlap + magnitude.

Where \(a\) and \(b\) are circles:

\( r_{sum} = r_a + r_b\)

@@ -87,10 +105,14 @@

Circle To Circle Collision Detection Algorithm

Collision Response

- A collision response occurs after a collision is detected and is used to change certain attributes regarding each of the circles. For example, we could make the circles bounce off of one - another when the collision occurs. In this article, we will only consider a simplified collision response meaning momentum will not be accurately represented. To properly position each of - the circles, we can use the depth that we found previously scaled along the position delta vector to offset each of the circles equally. Each circle is offset with a magnitude half of the - depth as we want to move each circle and equal distance apart. + A collision response occurs after a collision is detected and is used to change certain + attributes regarding each of the circles. For example, we could make the circles bounce + off of one another when the collision occurs. In this article, we will only consider a + simplified collision response meaning momentum will not be accurately represented. To + properly position each of the circles, we can use the depth that we found previously + scaled along the position delta vector to offset each of the circles equally. Each circle + is offset with a magnitude half of the depth as we want to move each circle and equal + distance apart.

\( \vec{d} = \vec{b_{pos}} - \vec{a_{pos}} \)

\( \hat{d} = \frac{\vec{d}}{|\vec{d}|} \)

@@ -104,13 +126,20 @@

Collision Response

Placeholder Diagram

- Notice the fact that the offset / delta vector we used to move the circles are perpendicular to the tangent line of the point the offset vector's axis intersects. The unit vector of this - offset is the same as the "normal" vector that faces towards the opposing circle thus defining a "normal" vector as one that lays perpendicular to a face. Also notice that there are two - vectors that are similar to our offset vector: the one we just defined and one that lays on the opposite side of the collision (just with a inverse or opposing direction). This property of - offsetting by the normals and parallel normals and faces will be used later on during collision detection between polygons. + Notice the fact that the offset / delta vector we used to move the circles are + perpendicular to the tangent line of the point the offset vector's axis intersects. The + unit vector of this offset is the same as the "normal" vector that faces towards the + opposing circle thus defining a "normal" vector as one that lays perpendicular to a face. + Also notice that there are two vectors that are similar to our offset vector: the one we + just defined and one that lays on the opposite side of the collision (just with a inverse + or opposing direction). This property of offsetting by the normals and parallel normals + and faces will be used later on during collision detection between polygons.

Simulation

-

Using the math previously described, we can make a physics simulation to describe collision detection and response.

+

+ Using the math previously described, we can make a physics simulation to describe + collision detection and response. +


Click to spawn in balls

Simulation data-default-tab="html,result" data-slug-hash="wvNPYGK" data-user="WaffleCake-the-decoder" - style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em" + style=" + height: 300px; + box-sizing: border-box; + display: flex; + align-items: center; + justify-content: center; + border: 2px solid; + margin: 1em 0; + padding: 1em; + " > See the Pen Untitled by WaffleCake (@WaffleCake-the-decoder) - on CodePen.See the Pen + Untitled by + WaffleCake (@WaffleCake-the-decoder) on CodePen.

- Click to open in new tab + Click to open in new tab
diff --git a/projects/Physics/BallCollisionOptimization/article.txt b/projects/Physics/BallCollisionOptimization/article.txt deleted file mode 100644 index c1dd2b7..0000000 --- a/projects/Physics/BallCollisionOptimization/article.txt +++ /dev/null @@ -1,2 +0,0 @@ -Limitation of Brute Force Circle Collision -You may have noticed the fact that spawning a lot of balls in the previous article's simulation quickly negatively impacts the performance of the simulation. The previous simulation took a brute-force approach to checking collision. Each ball is compared with every other ball meaning the number of comparisons quickly increases as the number of balls increases (in this case the number of comparisons is equal to \( n^2 \) where n is the number of balls present). \ No newline at end of file diff --git a/projects/Physics/BoxCollision/AABBCollision b/projects/Physics/BoxCollision/AABBCollision deleted file mode 160000 index 4c8a4fe..0000000 --- a/projects/Physics/BoxCollision/AABBCollision +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4c8a4fe4d48172dce718789fa32900d8431e522b