Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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 comentarios
Jan
Jan el 27 de Oct. de 2022
Editada: Jan el 27 de Oct. de 2022
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 el 27 de Oct. de 2022
Editada: Torsten el 27 de Oct. de 2022
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.

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 27 de Oct. de 2022
Editada: Jan el 27 de Oct. de 2022
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.

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by