From a00c0aab1eb5a7a55bef8ca08115bdd722ab5699 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Sun, 16 May 2021 19:50:15 -0400 Subject: Moved the frontend directory up so that it no longer exists --- 2d/_collisions/rectangle_rectangle.html.content | 77 +++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 2d/_collisions/rectangle_rectangle.html.content (limited to '2d/_collisions/rectangle_rectangle.html.content') diff --git a/2d/_collisions/rectangle_rectangle.html.content b/2d/_collisions/rectangle_rectangle.html.content new file mode 100644 index 0000000..2cc5847 --- /dev/null +++ b/2d/_collisions/rectangle_rectangle.html.content @@ -0,0 +1,77 @@ + + +
+

Rectangle intersection with a Rectangle

+
+

Algorithm

+

+ For each line segment that your rectangle could be intersecting with, + do the following: +

    +
  1. + For each corner of your rectangle, check if the distance from that point to the line is less than some epsilon, where epsilon is a reasonable small number (usually a 1 or 2 units, depending on the size of your lines). +
  2. +
  3. + To check each point, use the "distance from point to line segment" formula, which can be found here (I will not derive it just yet) +
  4. +
  5. + If a collision is found, we have all of the information required to solve the collision: +
      +
    • + Collision Normal: This is the perpendicular to the line segment, which can be found by: + +
      +Vector2 getNormalToLineSegment(LineSegment* segment) {
      +    Vector2 direction = segment->end - segment->start;
      +    return *Vector2 { -direction.y, direction.x }).normalize();
      +}
      +				
      +
      +
    • +
    • + First Point of Application: Get the vector from the center of the rectangle (most like your position) to the corner which intersected. +
    • +
    • + Second Point of Application: Get vector from center of line to the corner which intersected. +
    • +
    +
  6. +
+

+
+
+

+ Live Example +

+
+ + + +
+ +
+
-- cgit v1.2.1