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

10 次查看(过去 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