Main Content

checkCollision

두 기하 도형이 충돌하는지 검사

R2019b 이후

설명

collisionStatus = checkCollision(geom1,geom2)는 두 개의 볼록 기하 도형 geom1geom2 사이의 충돌 상태를 반환합니다. 두 기하 도형이 지정된 자세에서 충돌하는 경우 collisionStatus1입니다. 함수가 충돌을 찾지 못하면 collisionStatus0입니다.

예제

[collisionStatus,sepdist,witnesspts] = checkCollision(geom1,geom2)는 함수가 두 기하 도형 사이의 충돌을 찾지 못한 경우 각 도형의 최소 거리 sepdist와 감시점 witnesspts를 반환합니다.

예제

모두 축소

이 예제에서는 두 충돌 기하 도형의 충돌 상태를 검사하는 방법을 보여줍니다.

상자 충돌 기하 도형을 생성합니다.

bx = collisionBox(1,2,3);

원통 충돌 기하 도형을 생성합니다.

cy = collisionCylinder(3,1);

원통을 x축을 따라 2만큼 평행 이동합니다.

T = trvec2tform([2 0 0]);
cy.Pose = T;

두 기하 도형을 플로팅합니다.

show(cy)
hold on
show(bx)
xlim([-5 5])
ylim([-5 5])
zlim([-5 5])
hold off

Figure contains an axes object. The axes object with xlabel X, ylabel Y contains 2 objects of type patch.

충돌 상태를 검사합니다. 상태가 플롯과 일치하는지 확인합니다.

[areIntersecting,dist,witnessPoints] = checkCollision(bx,cy)
areIntersecting = 1
dist = NaN
witnessPoints = 3×2

   NaN   NaN
   NaN   NaN
   NaN   NaN

x축을 따라 3만큼, z축을 따라 아래 방향으로 4만큼 평행 이동합니다. 상자와 원통이 충돌하지 않는지 확인합니다.

T = trvec2tform([0 3 -4]);
bx.Pose = T;
[areIntersecting,dist,witnessPoints] = checkCollision(bx,cy)
areIntersecting = 0
dist = 2
witnessPoints = 3×2

    0.4286    0.4286
    2.0000    2.0000
   -2.5000   -0.5000

상자와 원통, 두 기하 도형 사이의 최소 거리를 나타내는 선분을 플로팅합니다.

show(cy)
hold on
show(bx)
wp = witnessPoints;
plot3([wp(1,1) wp(1,2)], [wp(2,1) wp(2,2)], [wp(3,1) wp(3,2)], 'bo-')
xlim([-5 5])
ylim([-5 5])
zlim([-5 5])
hold off

Figure contains an axes object. The axes object with xlabel X, ylabel Y contains 3 objects of type patch, line.

충돌 캡슐을 2개 생성합니다. 한 캡슐을 원점에 놓고, 다른 캡슐의 자세를 y축 상에서 원점으로부터 3만큼 떨어진 곳에 설정합니다. 캡슐을 표시합니다.

cc1 = collisionCapsule(1,4);
cc2 = collisionCapsule(1,4);
cc2.Pose = trvec2tform([0 3 0]);
show(cc1);
hold on
show(cc2);
axis auto
hold off

Figure contains an axes object. The axes object with xlabel X, ylabel Y contains 2 objects of type patch.

두 충돌 캡슐 간의 충돌을 검사합니다. 시각적으로 보면 둘이 충돌하지 않으므로 함수는 실수 값의 분리 거리와 감시점을 반환해야 합니다. 분리 거리와 감시점을 표시합니다.

[isColliding,separationDist,witnessPts] = checkCollision(cc1,cc2);
disp("Separation Distance: " + num2str(separationDist))
Separation Distance: 1
disp("Capsule 1 Witness Point (X Y Z): " + num2str(witnessPts(:,1)'))
Capsule 1 Witness Point (X Y Z): 0  1 -2
disp("Capsule 2 Witness Point (X Y Z): " + num2str(witnessPts(:,2)'))
Capsule 2 Witness Point (X Y Z): 0  2 -2

두 번째 캡슐을 z축 상에서 90도 회전합니다.

cc2.Pose(1:3,1:3) = eul2rotm([0 0 pi/2]);
show(cc1);
hold on
show(cc2);
axis auto

Figure contains an axes object. The axes object with xlabel X, ylabel Y contains 2 objects of type patch.

캡슐 간의 충돌을 다시 검사합니다. 둘이 충돌하고 있으므로 함수는 분리 거리와 감시점을 NaN으로 반환합니다.

[isColliding,separationDist,witnessPts] = checkCollision(cc1,cc2);
disp("Separation Distance: " + num2str(separationDist))
Separation Distance: NaN
disp("Capsule 1 Witness Point (X Y Z): " + num2str(witnessPts(:,1)'))
Capsule 1 Witness Point (X Y Z): NaN  NaN  NaN
disp("Capsule 2 Witness Point (X Y Z): " + num2str(witnessPts(:,2)'))
Capsule 2 Witness Point (X Y Z): NaN  NaN  NaN

입력 인수

모두 축소

첫 번째 충돌 기하 도형으로, 다음 충돌 기하 도형 객체 중 하나로 지정됩니다.

충돌 기하 도형으로, 다음 충돌 기하 도형 객체 중 하나로 지정됩니다.

출력 인수

모두 축소

충돌 상태로, 0 또는 1로 반환됩니다. 두 기하 도형이 충돌하는 경우 collisionStatus1입니다. 그렇지 않으면 값은 0입니다.

데이터형: double

충돌 기하 도형 간의 최소 거리로, 실수로 반환됩니다. 감시점 witnesspts를 연결하는 선분이 두 기하 도형 사이의 최소 거리를 결정합니다. 두 기하 도형이 충돌하는 경우 sepdistNaN입니다.

데이터형: double

각 기하 도형의 감시점으로, 3×2 행렬로 반환됩니다. 각 열은 대응하는 기하 도형 geom1 또는 geom2에 있는 감시점의 위치입니다. 두 감시점을 연결하는 선분의 길이는 septdist입니다. 두 기하 도형이 충돌하는 경우 witnesspts의 모든 요소는 NaN입니다.

데이터형: double

제한 사항

  • 최소 거리가 10-5미터 미만이면 충돌 검사 결과를 신뢰할 수 없습니다.

참고 문헌

[1] Gilbert, E.G., D.W. Johnson, and S.S. Keerthi. "A fast procedure for computing the distance between complex objects in three-dimensional space." IEEE Journal on Robotics and Automation 4, no. 2 (April 1988): 193–203. https://doi.org/10.1109/56.2083.

확장 기능

C/C++ 코드 생성
MATLAB® Coder™를 사용하여 C 코드나 C++ 코드를 생성할 수 있습니다.

버전 내역

R2019b에 개발됨