How to detect when 2 surface plots collide ?

6 views (last 30 days)
Hi,
I am creating a pipe work system using matlab script where the pipe is represented using surface plot. I want to be able to flag up a warning when 2 surface plots (pipes) clash with each other.
The script determins the direction of the pipe by searching the workspace data for pipe start nodes (SN) and end nodes (EN) (added to workspace before hand). It will then do the checks SNx - ENx~=0 , SNy-ENy~=0, SNz-ENz~=0. depending on the check results the pipe will be plotted in the order of X-section (if check ~=0), Y- section (if check ~=0) then Z- section (if check ~=0).
The 2 pipes I have clashing, 1 is only X-direction section of pipe and the clashing pipe is only Y-direction section of pipe.
looking for some code to add to my script that will flag up the collision ?
thank you.

Accepted Answer

Harsha Vardhan
Harsha Vardhan on 17 Nov 2023
Hi,
I understand that you want to detect a collision between two surface plots (representing pipes) in MATLAB.
There are a few strategies you can employ.
Bounding Box Intersection Method: This method involves creating a bounding box around each pipe segment and then checking if these boxes intersect. This is a more straightforward approach but can be less accurate if your pipes are very thin or have complex shapes.
Steps:
  • Calculate the axis-aligned bounding box (AABB) for each pipe segment. The AABB can be defined by the minimum and maximum coordinates along each axis.
  • Check if the AABBs of two pipe segments intersect. AABBs intersect if they overlap along all three axes (X, Y, Z).
Discretization and Spatial Hashing: This method involves discretizing the space into a grid and marking which cells are occupied by each pipe. Then, you can easily check if a cell is occupied by more than one pipe.
Steps:
  • Discretize your workspace into a 3D grid.
  • For each pipe segment, determine which grid cells it occupies.
  • Check for collisions by identifying grid cells that are occupied by more than one pipe.
Using ‘checkCollision' function from Robotic System Toolbox: This function checks if 2 geometries are in collision. You may have to map your surface plot to those geometries. Please find the documentation here - https://www.mathworks.com/help/robotics/ref/checkcollision.html
Hope this helps in resolving your query!

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!