필터 지우기
필터 지우기

How do i check if elements from my rows of vector are within range of one another

조회 수: 1 (최근 30일)
I'm trying to write a code for collision detection of sphere's in my project. I have vector containing values for the edges of each sphere on just the x-axis. how do i check if any of the rows are within the range of one another? e.g:
There's a possible collision in row 4 and 5.
I'm really not sure how to go about this so any help would be apprietiated thanks.
  댓글 수: 2
Jan
Jan 2022년 10월 27일
편집: Jan 2022년 10월 27일
Colliding sphere should be easy to detect using the positions of their centers and their radius.
What do yo call "being in the range of a vector"? What are "values for the edges on the x-axis"? What is the mathematical argument for assuming collisions in the rows 4 and 5? Write this down to have an important part of the solution.
By the way, posting the data as text would allow to use them by copy&paste for a solution. A screen shot is the worst method to post code or data in the forum.
Torsten
Torsten 2022년 10월 27일
편집: Torsten 2022년 10월 27일
Hint:
For that M(i,:) and M(j,:) overlap, both max(M(i,:)) < min(M(j,:)) and max(M(j,:)) < min(M(i,:)) must be false.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2022년 10월 27일
편집: Jan 2022년 10월 27일
With some bold guessing of what you want to achieve:
X = [ 0.2734, 0.1734; ...
-0.1671, -0.2671; ...
0.0753, 0.0247; ...
-0.2240, -0.3240; ...
-0.2640, -0.3640];
X = sort(X, 2); % Care for order of coordinates
plot(X.', [1:5; 1:5])
ylim([0, 10])
X1 = X(:, 1);
X2 = X(:, 2);
overlap = (X1 > X1.' & X1 < X2.') | (X2 > X1.' & X2 < X2.')
overlap = 5×5 logical array
0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 1 0 1 0 1 0
Meaning: The 2nd row indicates, that the interval 2 overlaps with the intervals 4 and 5. The 5th row means, that the 5th interval overlaps with the intervals 2 and 4.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by