From: Steve on 30 Jul 2010 21:23 ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <8887b212-9387-4b54-af5f-6f8e388aa410(a)j8g2000yqd.googlegroups.com>... > Are you (1) going to place all the blue lines first and then check > (like your example), or are you (2) going to place one line at each > iteration of a loop and then check against that one line (kind of like > your explanation that mentioned a loop) and then break out of the loop > if the latest line is within the radius? > > A dumb brute force way is to write the lines into a 2D matrix (image) > and then use the Euclidean Distance Transform (bwdist() which is in > the Image Processing Toolbox), but I bet there's a more clever > analytical method. Thanks for your answer. Every line is growing over time and i want to check which lines are colliding and stop the growth of these lines. Like in my example. I'm using such a 2D matrix at the moment, but when the lines get very long this matrix gets very huge, sometimes more than the allowed variable size allowed. So I'm looking for an analytical way. This is really tricky...
From: ImageAnalyst on 30 Jul 2010 23:13 Then I'd probably do something like this: for each blue line calculate distance of blue endpoints to each red endpoint if any of those distances <= radius This is the really trivial case. There IS definitely an intersection so you can bail out of loop else There MAY be an intersection IN BETWEEN the blue endpoints This is the more complicated case for each red endpoint, calculate perpendicular distance to blue line as if blue line were infinitely long using standard geometrical "point-line distance" equations. if (perpendicular distance < Radius) && (blue midpoint coordinates are in between blue endpoints) There is an intersection in the middle of the blue line somewhere bail out of loop else This line does not intersect anywhere end % of if end % of for loop to check red endpoints end end % of for loop over all blue lines. You can check if the blue mid point is between the blue endpoints just by doing this: if (midx > minEnd1x) && (midx < maxEnd1x) && ... (midy > minEnd1y) && (midy < maxEnd1y) Then the "in between point" is really in between the actual endpoints. end Ref for point-line distance: http://www.intmath.com/Plane-analytic-geometry/Perpendicular-distance-point-line.php
From: Bruno Luong on 31 Jul 2010 04:33 "Steve " <stefan.griesser(a)alumni.unileoben.ac.at> wrote in message <i2un88$2og$1(a)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+'); > There are few tools in FEX that might ease to carry out the task, such as this one (not tested myself): http://www.mathworks.com/matlabcentral/fileexchange/28268-calculation-of-distances-from-a-given-set-of-points-to-a-set-of-segments Bruno
From: Steve on 31 Jul 2010 05:00 > There are few tools in FEX that might ease to carry out the task, such as this one (not tested myself): > http://www.mathworks.com/matlabcentral/fileexchange/28268-calculation-of-distances-from-a-given-set-of-points-to-a-set-of-segments > > Bruno Bruno, thank you very much for that link. This is exactly what I needed. Works perfect!
First
|
Prev
|
Pages: 1 2 Prev: frame based input of RC digital low pas filter Next: PCA problem and Memory error |