collision detection with rectangles or circles

조회 수: 2 (최근 30일)
Sami Al-Abbar
Sami Al-Abbar 2016년 4월 18일
답변: Sami Al-Abbar 2016년 4월 18일
I am using the functions "rectangle" and "viscircles" in order to create objects in a graph.
obstacle_rect = rectangle('position',[6 2 2 2],'EdgeColor','r','LineWidth',2)
centers = [2.5 5; 4 3.5; 5.4 8.3; 8.2 6.22;];
radii = [0.5; 0.5; 1.5; 0.8];
obstacle_round = viscircles(centers, radii+r)
Now when plotting new vertices in the graph, I would like to test whether this vertex is inside the object or not (collision detection). I was thinking of doing this by calculating the distance between the vertex and some coordinates of the object. The issue is I don't know how to extract information out of the rectangles or circles as they are saved as a "group" in the workspace. I need a way to access the array 'position' somehow but in the help section I couldn't find anything on it.
Additionally, I would like to know if there might be a better way to determine whether a vertex is in collision with an object.
(I am using a student edition of Matlab 2016a with pretty much all of the available toolboxes.) Let me know if there is any information missing in order for this to be answered.
Thanks in advance.

답변 (1개)

Sami Al-Abbar
Sami Al-Abbar 2016년 4월 18일
It appears I needed the get() function:
X = get(obstacle_rect,'position');
in order to get the the position data.
However, I would still like some insight into a good method of collision detection with these obstacles.

Community Treasure Hunt

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

Start Hunting!

Translated by