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
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.
采纳的回答
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.')
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!