2D Collision Detection

4 次查看(过去 30 天)
Georg Söllinger
Georg Söllinger 2016-10-28
评论: Michael 2017-4-20
Hello Guys,
I am doing a collision analysis in 2D. More precisely, I analyse the movement of a specific robot head on a concave tool. I have already programmed the movement of the robot head on the tool surface. The latter is parameterized over its whole length with an aequidistant parameter t. The robot heads geometry is defined by a set of x-y-coordinates. The collision is analyzed as follows: I analyze for each parameter (first loop) the intersection of two point-pairs of each the tool (ax = x(t), bx = x(t+1), ay = y(t), by = y(t+1) -> second loop) and the robot head (cx = x(j), dx = x(j+1), cy = y(j), dy = y(j+1) -> third loop). Then I calculate the following:
a = ax - bx;
b = movement_geometry(i+1,1) - movement_geometry(i,1);
c = az - bz;
d = movement_geometry(i+1,2) - movement_geometry(i,2);
e = ax - movement_geometry(i,1);
f = az - movement_geometry(i,2);
if i == 560
j = 1;
end
det = a * d - b * c;
s = 1 / det * ( d * e - b * f);
t = 1 / det * (-c * e + a * f);
if (s <= 1 && s >= 0 ) && (t <= 1 && t >= 0)
collision_boolean = 1;
break
else
collision_boolean = 0;
end
end
This concept works, but as you can expect, it is very very slow. Is there a way to avoid the loops. The parameter t is of the size 300, the size of the robot head is 4000. Thus, there are 300*300*4000 steps to compute....
I cant find a way to analyze the stuff with simple matrix operations, do you have some better ideas or alternative ways for this computation?
Thanks in advance, I am looking forward to your help!
Best Wishes, Georg
  1 个评论
Michael
Michael 2017-4-20
You are missing the top of the loop and some toy values for the variables. There are a stack of strategies. You could compile the code. You could vectorize it. You could pre-compute and make it a table lookup. You are probably much better off to rely on built-ins than on homebrew, so use an builtin determinant. Do you know "movement geometry" before the loop? If so then you can pull a...f out of the loop. Why are you resetting "j" at 560? Do you predeclare your variables?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by