How to filter out lines that intersect other lines?

3 views (last 30 days)
I have about 14 lines stored in a matrix but are not plotted, and these lines create 84 intersections. So I am plotting 84 lines that emanate from the origin and connect to each of the points of intersection. Some of these lines travel a while to reach the intersection, and a few travel a short distance and do not cross any other lines before reaching the point of intersection. Is there any way to filter out all of the lines that cross other lines, and only keep the unobstructed lines plotted?

Answers (1)

Image Analyst
Image Analyst on 19 Jun 2015
How are they stored?
  • Do you have a 14 by 4 list of line segment endpoints (2 x,y end points per line segment)?
  • Or do you have a digital image with the lines burned in as pixels?
  • Or do you have the equations of the lines (slopes and intercepts)?
If it's an image, you can use bwmorph() with the 'branchpoints' option to find crossings.
  2 Comments
Aditya Shetty
Aditya Shetty on 19 Jun 2015
I have them stored in a 14 x 2 matrix that contains each line's slope and y-intercept.
Image Analyst
Image Analyst on 19 Jun 2015
Aditya, unless the lines are parallel, then they will cross. Check column 1 for duplicates using sort() and diff(), or using unique(), or just == operator.
To find the crossing points, it's just simple high school algebra. You have two lines, so set them equal to each other to find the common x point
ax + b = cx + d
(a-c)x = d-c
x = (d-c)/(a-c)
So don't you think you could add 13 rows where you'll give the x value of the crossing point for each of the other points? Sure you could - it's easy . I have confidence in you. Let us know if you can't. Then to get the y values, just stick that x into either of the two equations.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!