フィルターのクリア

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

1 回表示 (過去 30 日間)
Victor Falola
Victor Falola 2022 年 10 月 27 日
編集済み: Jan 2022 年 10 月 27 日
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 Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by