Back

DiscreteIntersection

The DiscreteIntersection class is part of the SOFA (Simulation Open-Framework Architecture) framework and serves as an implementation for discrete collision detection between various geometric models, primarily cubes and spheres.

abstract
The DiscreteIntersection component detects intersections between geometric shapes such as cubes and spheres using discrete methods, providing fundamental capabilities for proximity and collision detection within the SOFA framework.
sheet
# DiscreteIntersection ## Overview DiscreteIntersection is a component in the SOFA framework designed to perform discrete collision detection between various geometric models, primarily cubes and spheres. It inherits from the Intersection class and implements virtual methods for intersection testing and computation. ## Mathematical Model ### Collision Detection Between Cubes For two cuboids represented by their bounding boxes with minimum and maximum coordinates given as vectors \(\text{minVect}_i = (x_{mi}, y_{mi}, z_{mi})\) and \(\text{maxVect}_i = (x_{Mi}, y_{Mi}, z_{Mi})\), where \(i=1,2\), the intersection test checks if there is any overlap along each axis. The conditions for no overlap are: - \(\text{minVect}_{1,x} > \text{maxVect}_{2,x} + d_{\text{alarm}}\) - \(\text{minVect}_{2,x} > \text{maxVect}_{1,x} + d_{\text{alarm}}\) Similar conditions apply for the y and z axes. ### Collision Detection Between Spheres For two spheres with centers at \(\text{center}_1 = (x_{c1}, y_{c1}, z_{c1})\) and \(\text{center}_2 = (x_{c2}, y_{c2}, z_{c2})\), respectively, and radii \(r_1\) and \(r_2\), the distance between their centers is given by: \[ d = ||\text{center}_2 - \text{center}_1||^2 \] The spheres are within alarm distance if: - \(d > (d_{\text{alarm}} + r_1 + r_2)^2\) If they intersect or are close enough, contact points and normal vectors are calculated as follows: - Normal vector: \( \mathbf{n} = (\text{center}_2 - \text{center}_1) / ||\text{center}_2 - \text{center}_1||\) - Contact point on sphere \(S_1\): \(\text{point}_1 = \text{center}_1 + r_1 * (-\mathbf{n})\) - Contact point on sphere \(S_2\): \(\text{point}_2 = \text{center}_2 + r_2 * \mathbf{n}\)
name
DiscreteIntersection
category
Collision Detection
description
The DiscreteIntersection class is part of the SOFA (Simulation Open-Framework Architecture) framework and serves as an implementation for discrete collision detection between various geometric models, primarily cubes and spheres.
detailed_description
This component extends from two core classes: `core::collision::Intersection` and `core::collision::BaseIntersector`. It defines a series of methods to test intersection and compute contact points between different types of collision objects. The primary geometries considered here are cubes (`Cube`) and spheres (`Sphere`, `RigidSphere`).
methods
{
  "computeIntersection(Cube\u0026, Cube\u0026)": "Computes contact information for two intersecting cubes. In this particular implementation, it is a placeholder and returns 0 without performing any computation.",
  "computeIntersection(RigidSphere\u0026, RigidSphere\u0026)": "Computes contact information between two intersecting rigid spheres using the template function `computeIntersectionSphere`.",
  "computeIntersection(Sphere\u0026, RigidSphere\u0026)": "Computes contact information for intersecting sphere and rigid sphere pair using the template function `computeIntersectionSphere`.",
  "computeIntersection(Sphere\u0026, Sphere\u0026)": "Computes contact information for two intersecting spheres using the `computeIntersectionSphere` template function.",
  "testIntersection(Cube\u0026 cube1, Cube\u0026 cube2)": "Tests if two cubes intersect based on their bounding boxes considering an alarm distance derived from the current intersection context.",
  "testIntersection(RigidSphere\u0026 sph1, RigidSphere\u0026 sph2)": "Similar to `testIntersection(Sphere\u0026 sph1, Sphere\u0026 sph2)` but applies for rigid spheres.",
  "testIntersection(Sphere\u0026 sph1, RigidSphere\u0026 sph2)": "Tests intersection between a sphere and a rigid sphere by calling `testIntersectionSphere` with an alarm distance from current intersection context.",
  "testIntersection(Sphere\u0026 sph1, Sphere\u0026 sph2)": "Tests if two spheres intersect by calling the template function `testIntersectionSphere` with alarm distance parameter derived from current intersection context."
}
template_functions
{
  "bool testIntersectionSphere(SphereType1\u0026 sph1, SphereType2\u0026 sph2)": "A templated helper function that tests intersection between two spheres of different types by checking if their combined radius plus alarm distance exceeds the square of the distance between their centers.",
  "int computeIntersectionSphere(SphereType1\u0026, SphereType2\u0026)": "Computes contact information for intersecting sphere pairs. It adds a new `DetectionOutput` to the output vector containing normal, points of contact, value (distance), and element indices."
}
usage_example
This component would be used in a simulation environment where it's necessary to detect collisions between rigid bodies modeled as cubes or spheres. The detection can be part of a broader collision handling system within SOFA.
note
The `DiscreteIntersection` class supports dynamic extension through the use of an `IntersectorMap`, allowing new intersector methods to be added at runtime for different types of geometric models.
maths
The DiscreteIntersection class in the SOFA framework is designed to perform discrete collision detection between different geometric shapes, namely cubes and spheres. It employs basic geometric principles and concepts from linear algebra for its operations. ### Collision Detection Between Cubes For cubes, the method `testIntersection(collision::geometry::Cube& cube1, collision::geometry::Cube& cube2)` checks if two cuboids are in proximity or overlap within a certain alarm distance. This is done by comparing each coordinate of their bounding boxes: - Let \(B_1\) and \(B_2\) be the two cubes with minimum and maximum coordinates given as vectors \( ext{minVect}_i = (x_{mi}, y_{mi}, z_{mi})\) and \( ext{maxVect}_i = (x_{Mi}, y_{Mi}, z_{Mi})\), where \(i=1,2\). - The algorithm checks if there is any overlap along each axis. For the intersection to be true, none of the following conditions should hold: - \( ext{minVect}_{1,x} > ext{maxVect}_{2,x} + d_{ ext{alarm}}\) - \( ext{minVect}_{2,x} > ext{maxVect}_{1,x} + d_{ ext{alarm}}\) - Similar conditions for the y and z axes. The function `computeIntersection(collision::geometry::Cube& cube1, collision::geometry::Cube& cube2)` currently does not compute any intersections but instead returns a constant value of 0. This implies that it is either a placeholder or needs to be implemented based on specific requirements for calculating contact points and normal vectors. ### Collision Detection Between Spheres For spheres, the method `testIntersection(collision::geometry::Sphere& sph1, collision::geometry::Sphere& sph2)` checks if two spheres are within an alarm distance of each other. The function `computeIntersection(collision::geometry::Sphere& sph1, collision::Sphere& sph2)` computes contact points and normal vectors when the spheres intersect or are close enough. - Let \(S_1\) and \(S_2\) be two spheres with centers at \( ext{center}_1 = (x_{c1}, y_{c1}, z_{c1})\) and \( ext{center}_2 = (x_{c2}, y_{c2}, z_{c2})\), respectively, and radii \(r_1\) and \(r_2\). - The distance between the centers of the spheres is given by: \[ ext{dist} = || ext{center}_2 - ext{center}_1||^2 \] - If \( ext{dist} > (d_{ ext{alarm}} + r_1 + r_2)^2\), the spheres are not within alarm distance, and no intersection is reported. - Otherwise, contact points and normal vectors are calculated: - Normal vector: \( extbf{n} = ( ext{center}_2 - ext{center}_1) / || ext{center}_2 - ext{center}_1||\) - Contact point on sphere \(S_1\): \( ext{point}_1 = ext{center}_1 + r_1 * (- extbf{n})\) - Contact point on sphere \(S_2\): \( ext{point}_2 = ext{center}_2 + r_2 * extbf{n}\) - The detection value is set to the difference between the distance and the sum of radii, adjusted by a contact distance \(d_{ ext{contact}}\). ### Collision Detection Between Spheres and RigidSpheres Similar to sphere-sphere interactions, the methods `testIntersection(Sphere& sph1, RigidSphere& sph2)` and `computeIntersection(Sphere& sph1, RigidSphere& sph2)` handle collision detection between a sphere and a rigid sphere by using the same principles as above. Overall, these operations provide fundamental capabilities for detecting proximity or collisions between geometric shapes in discrete time steps within the SOFA framework.
{
  "name": "DiscreteIntersection",
  "main": {
    "name": "DiscreteIntersection",
    "namespace": "sofa::component::collision::detection::intersection",
    "module": "Sofa.Component.Collision.Detection.Intersection",
    "include": "sofa/component/collision/detection/intersection/DiscreteIntersection.h",
    "doc": "Detect intersection using discrete methods.",
    "inherits": [
      "Intersection"
    ],
    "templates": [],
    "data_fields": [],
    "links": [],
    "methods": [
      {
        "name": "findIntersector",
        "return_type": "core::collision::ElementIntersector *",
        "params": [
          {
            "name": "object1",
            "type": "core::CollisionModel *"
          },
          {
            "name": "object2",
            "type": "core::CollisionModel *"
          },
          {
            "name": "swapModels",
            "type": "bool &"
          }
        ],
        "is_virtual": true,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "testIntersection",
        "return_type": "bool",
        "params": [
          {
            "name": "cube1",
            "type": "collision::geometry::Cube &"
          },
          {
            "name": "cube2",
            "type": "collision::geometry::Cube &"
          },
          {
            "name": "currentIntersection",
            "type": "const core::collision::Intersection *"
          }
        ],
        "is_virtual": true,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "computeIntersection",
        "return_type": "int",
        "params": [
          {
            "name": "cube1",
            "type": "collision::geometry::Cube &"
          },
          {
            "name": "cube2",
            "type": "collision::geometry::Cube &"
          },
          {
            "name": "contacts",
            "type": "OutputVector *"
          },
          {
            "name": "currentIntersection",
            "type": "const core::collision::Intersection *"
          }
        ],
        "is_virtual": true,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "testIntersection",
        "return_type": "bool",
        "params": [
          {
            "name": "sph1",
            "type": "collision::geometry::Sphere &"
          },
          {
            "name": "sph2",
            "type": "collision::geometry::Sphere &"
          },
          {
            "name": "currentIntersection",
            "type": "const core::collision::Intersection *"
          }
        ],
        "is_virtual": true,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "computeIntersection",
        "return_type": "int",
        "params": [
          {
            "name": "sph1",
            "type": "collision::geometry::Sphere &"
          },
          {
            "name": "sph2",
            "type": "collision::geometry::Sphere &"
          },
          {
            "name": "contacts",
            "type": "OutputVector *"
          },
          {
            "name": "currentIntersection",
            "type": "const core::collision::Intersection *"
          }
        ],
        "is_virtual": true,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "testIntersection",
        "return_type": "bool",
        "params": [
          {
            "name": "sph1",
            "type": "collision::geometry::RigidSphere &"
          },
          {
            "name": "sph2",
            "type": "collision::geometry::RigidSphere &"
          },
          {
            "name": "currentIntersection",
            "type": "const core::collision::Intersection *"
          }
        ],
        "is_virtual": true,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "computeIntersection",
        "return_type": "int",
        "params": [
          {
            "name": "sph1",
            "type": "collision::geometry::RigidSphere &"
          },
          {
            "name": "sph2",
            "type": "collision::geometry::RigidSphere &"
          },
          {
            "name": "contacts",
            "type": "OutputVector *"
          },
          {
            "name": "currentIntersection",
            "type": "const core::collision::Intersection *"
          }
        ],
        "is_virtual": true,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "testIntersection",
        "return_type": "bool",
        "params": [
          {
            "name": "sph1",
            "type": "collision::geometry::Sphere &"
          },
          {
            "name": "sph2",
            "type": "collision::geometry::RigidSphere &"
          },
          {
            "name": "currentIntersection",
            "type": "const core::collision::Intersection *"
          }
        ],
        "is_virtual": true,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "computeIntersection",
        "return_type": "int",
        "params": [
          {
            "name": "sph1",
            "type": "collision::geometry::Sphere &"
          },
          {
            "name": "sph2",
            "type": "collision::geometry::RigidSphere &"
          },
          {
            "name": "contacts",
            "type": "OutputVector *"
          },
          {
            "name": "currentIntersection",
            "type": "const core::collision::Intersection *"
          }
        ],
        "is_virtual": true,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "testIntersectionSphere",
        "return_type": "bool",
        "params": [
          {
            "name": "sph1",
            "type": "SphereType1 &"
          },
          {
            "name": "sph2",
            "type": "SphereType2 &"
          },
          {
            "name": "alarmDist",
            "type": "const SReal"
          }
        ],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "protected"
      },
      {
        "name": "computeIntersectionSphere",
        "return_type": "int",
        "params": [
          {
            "name": "sph1",
            "type": "SphereType1 &"
          },
          {
            "name": "sph2",
            "type": "SphereType2 &"
          },
          {
            "name": "contacts",
            "type": "DiscreteIntersection::OutputVector *"
          },
          {
            "name": "alarmDist",
            "type": "const SReal"
          },
          {
            "name": "contactDist",
            "type": "const SReal"
          }
        ],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "protected"
      }
    ]
  },
  "desc": {
    "name": "DiscreteIntersection",
    "category": "Collision Detection",
    "description": "The DiscreteIntersection class is part of the SOFA (Simulation Open-Framework Architecture) framework and serves as an implementation for discrete collision detection between various geometric models, primarily cubes and spheres.",
    "detailed_description": "This component extends from two core classes: `core::collision::Intersection` and `core::collision::BaseIntersector`. It defines a series of methods to test intersection and compute contact points between different types of collision objects. The primary geometries considered here are cubes (`Cube`) and spheres (`Sphere`, `RigidSphere`).",
    "methods": {
      "testIntersection(Cube& cube1, Cube& cube2)": "Tests if two cubes intersect based on their bounding boxes considering an alarm distance derived from the current intersection context.",
      "computeIntersection(Cube&, Cube&)": "Computes contact information for two intersecting cubes. In this particular implementation, it is a placeholder and returns 0 without performing any computation.",
      "testIntersection(Sphere& sph1, Sphere& sph2)": "Tests if two spheres intersect by calling the template function `testIntersectionSphere` with alarm distance parameter derived from current intersection context.",
      "computeIntersection(Sphere&, Sphere&)": "Computes contact information for two intersecting spheres using the `computeIntersectionSphere` template function.",
      "testIntersection(RigidSphere& sph1, RigidSphere& sph2)": "Similar to `testIntersection(Sphere& sph1, Sphere& sph2)` but applies for rigid spheres.",
      "computeIntersection(RigidSphere&, RigidSphere&)": "Computes contact information between two intersecting rigid spheres using the template function `computeIntersectionSphere`.",
      "testIntersection(Sphere& sph1, RigidSphere& sph2)": "Tests intersection between a sphere and a rigid sphere by calling `testIntersectionSphere` with an alarm distance from current intersection context.",
      "computeIntersection(Sphere&, RigidSphere&)": "Computes contact information for intersecting sphere and rigid sphere pair using the template function `computeIntersectionSphere`."
    },
    "template_functions": {
      "bool testIntersectionSphere(SphereType1& sph1, SphereType2& sph2)": "A templated helper function that tests intersection between two spheres of different types by checking if their combined radius plus alarm distance exceeds the square of the distance between their centers.",
      "int computeIntersectionSphere(SphereType1&, SphereType2&)": "Computes contact information for intersecting sphere pairs. It adds a new `DetectionOutput` to the output vector containing normal, points of contact, value (distance), and element indices."
    },
    "usage_example": "This component would be used in a simulation environment where it's necessary to detect collisions between rigid bodies modeled as cubes or spheres. The detection can be part of a broader collision handling system within SOFA.",
    "note": "The `DiscreteIntersection` class supports dynamic extension through the use of an `IntersectorMap`, allowing new intersector methods to be added at runtime for different types of geometric models."
  },
  "maths": {
    "maths": "The DiscreteIntersection class in the SOFA framework is designed to perform discrete collision detection between different geometric shapes, namely cubes and spheres. It employs basic geometric principles and concepts from linear algebra for its operations.\n\n### Collision Detection Between Cubes\nFor cubes, the method `testIntersection(collision::geometry::Cube& cube1, collision::geometry::Cube& cube2)` checks if two cuboids are in proximity or overlap within a certain alarm distance. This is done by comparing each coordinate of their bounding boxes:\n\n- Let \\(B_1\\) and \\(B_2\\) be the two cubes with minimum and maximum coordinates given as vectors \\(\text{minVect}_i = (x_{mi}, y_{mi}, z_{mi})\\) and \\(\text{maxVect}_i = (x_{Mi}, y_{Mi}, z_{Mi})\\), where \\(i=1,2\\).\n- The algorithm checks if there is any overlap along each axis. For the intersection to be true, none of the following conditions should hold:\n  - \\(\text{minVect}_{1,x} > \text{maxVect}_{2,x} + d_{\text{alarm}}\\)\n  - \\(\text{minVect}_{2,x} > \text{maxVect}_{1,x} + d_{\text{alarm}}\\)\n  - Similar conditions for the y and z axes.\n\nThe function `computeIntersection(collision::geometry::Cube& cube1, collision::geometry::Cube& cube2)` currently does not compute any intersections but instead returns a constant value of 0. This implies that it is either a placeholder or needs to be implemented based on specific requirements for calculating contact points and normal vectors.\n\n### Collision Detection Between Spheres\nFor spheres, the method `testIntersection(collision::geometry::Sphere& sph1, collision::geometry::Sphere& sph2)` checks if two spheres are within an alarm distance of each other. The function `computeIntersection(collision::geometry::Sphere& sph1, collision::Sphere& sph2)` computes contact points and normal vectors when the spheres intersect or are close enough.\n\n- Let \\(S_1\\) and \\(S_2\\) be two spheres with centers at \\(\text{center}_1 = (x_{c1}, y_{c1}, z_{c1})\\) and \\(\text{center}_2 = (x_{c2}, y_{c2}, z_{c2})\\), respectively, and radii \\(r_1\\) and \\(r_2\\).\n- The distance between the centers of the spheres is given by:\n  \\[ \text{dist} = ||\text{center}_2 - \text{center}_1||^2 \\]\n- If \\(\text{dist} > (d_{\text{alarm}} + r_1 + r_2)^2\\), the spheres are not within alarm distance, and no intersection is reported.\n- Otherwise, contact points and normal vectors are calculated:\n  - Normal vector: \\( \textbf{n} = (\text{center}_2 - \text{center}_1) / ||\text{center}_2 - \text{center}_1||\\)\n  - Contact point on sphere \\(S_1\\): \\(\text{point}_1 = \text{center}_1 + r_1 * (-\textbf{n})\\)\n  - Contact point on sphere \\(S_2\\): \\(\text{point}_2 = \text{center}_2 + r_2 * \textbf{n}\\)\n- The detection value is set to the difference between the distance and the sum of radii, adjusted by a contact distance \\(d_{\text{contact}}\\).\n\n### Collision Detection Between Spheres and RigidSpheres\nSimilar to sphere-sphere interactions, the methods `testIntersection(Sphere& sph1, RigidSphere& sph2)` and `computeIntersection(Sphere& sph1, RigidSphere& sph2)` handle collision detection between a sphere and a rigid sphere by using the same principles as above.\n\nOverall, these operations provide fundamental capabilities for detecting proximity or collisions between geometric shapes in discrete time steps within the SOFA framework."
  },
  "summary": {
    "abstract": "The DiscreteIntersection component detects intersections between geometric shapes such as cubes and spheres using discrete methods, providing fundamental capabilities for proximity and collision detection within the SOFA framework.",
    "sheet": "# DiscreteIntersection\n\n## Overview\nDiscreteIntersection is a component in the SOFA framework designed to perform discrete collision detection between various geometric models, primarily cubes and spheres. It inherits from the Intersection class and implements virtual methods for intersection testing and computation.\n\n## Mathematical Model\n### Collision Detection Between Cubes\nFor two cuboids represented by their bounding boxes with minimum and maximum coordinates given as vectors \\(\\text{minVect}_i = (x_{mi}, y_{mi}, z_{mi})\\) and \\(\\text{maxVect}_i = (x_{Mi}, y_{Mi}, z_{Mi})\\), where \\(i=1,2\\), the intersection test checks if there is any overlap along each axis. The conditions for no overlap are:\n- \\(\\text{minVect}_{1,x} > \\text{maxVect}_{2,x} + d_{\\text{alarm}}\\)\n- \\(\\text{minVect}_{2,x} > \\text{maxVect}_{1,x} + d_{\\text{alarm}}\\)\nSimilar conditions apply for the y and z axes.\n\n### Collision Detection Between Spheres\nFor two spheres with centers at \\(\\text{center}_1 = (x_{c1}, y_{c1}, z_{c1})\\) and \\(\\text{center}_2 = (x_{c2}, y_{c2}, z_{c2})\\), respectively, and radii \\(r_1\\) and \\(r_2\\), the distance between their centers is given by:\n\\[ d = ||\\text{center}_2 - \\text{center}_1||^2 \\]\nThe spheres are within alarm distance if:\n- \\(d > (d_{\\text{alarm}} + r_1 + r_2)^2\\)\nIf they intersect or are close enough, contact points and normal vectors are calculated as follows:\n- Normal vector: \\( \\mathbf{n} = (\\text{center}_2 - \\text{center}_1) / ||\\text{center}_2 - \\text{center}_1||\\)\n- Contact point on sphere \\(S_1\\): \\(\\text{point}_1 = \\text{center}_1 + r_1 * (-\\mathbf{n})\\)\n- Contact point on sphere \\(S_2\\): \\(\\text{point}_2 = \\text{center}_2 + r_2 * \\mathbf{n}\\)"
  }
}