|
"Steve " <stefan.griesser@alumni.unileoben.ac.at> wrote in message <i2un88$2og$1@fred.mathworks.com>...
> Hi all,
>
> I have a lot of line segments and I want to see if a specific line collides with another line segment within a certain radius.
>
> Here's an example:
>
> close all; clear;
> %
> % Generate the lines
> Lines = [0.4214,0.9079, 0.2558, 0.3329
> 0.5135, 0.8358, 0.6790, 0.5828
> 0.0861, 0.3706, 0.5698, 0.5780
> 0.7157, 0.2439, 0.4407, 0.2900
> 0.5632, 0.2852, 0.7828, 0.3689];
> %
> %
> %
> figure;
> axis image;
> hold on;
> %
> % Draw the lines (The first one in red)
> for k = 1:size(Lines,1)
> x = Lines(k, 1:2);
> y = Lines(k, 3:4);
> if (k==1)
> color = [1 0 0];
> else
> color = [0 0 1];
> end;
> line(x, y, 'Color', color);
> end;
> %
> %Plot the Radius
> Radius = 0.1;
> t = linspace(0, 2*pi, 100);
> xr = Lines(1,1) + Radius * cos(t);
> yr = Lines(1,3) + Radius * sin(t);
> plot(xr, yr, 'r');
> plot(Lines(1,1), Lines(1,3), 'r+');
>
> How can I calculate if the red line collides with any of the other lines (if any other line lies in that circle with Radius R)? I have more than 30000 Lines, and that is placed in a loop as well, so only a very efficient code would help!
>
> Thanks very much!
In 2 dimensions, you need to know if either
- either endpoint of a line segment is within the
specified radius of another segment.
- a pair of line segments cross, but the end points
are not close to the other line, so the previous test
will miss that pair of line segments.
Given 30000 line segments, good luck. Why do
I say this? Because not every thing you wish to
do will be easy to accomplish.
I would probably recommend use of a quad-tree
like decomposition, splitting the domain into
sub-domains. Then you need only worry about
intersections within a given sub-domain. Note
that some line segments may fall inside more
than one sub-domain.
John
|