Line fit between two curves.
Show older comments
Hey Guys,
I am trying to solve a problem regarding clearances and line fitting, around and through 2 curves.
The information I have is a coordinates of 2 parallel lines, resembling a pipe. Both these lines are not completely straight and bend at certain points.
The two line can be represented as so;
x1=[0 2 4.5 7 9];
y1=[0.7 2 4 5.5 7.5];
y2=y1+1;
plot(x1,y1,'-r')
hold on
plot(x1,y2,'-r')
grid on
I want the program to check whether a straight line of length 10 units will fit within these two line with out touching the edges. And if so how will this line sit within the two parallel lines.
The final image should look similar to this;
(add to end of previous code)
xb=[0.5 8.5];
yb=[1.5 7.5];
plot(xb,yb,'-b')
Please advice as to which commands, if any would be useful. Or what mathematical approach I should take to try and solve this.
Thanks,
6 Comments
Andrew Reibold
on 15 Aug 2013
What happens if there are multiple solutions? What solution is "best" (i.e., Hugging/close to the bottom line, farthest from each line as possible,[closertomiddle] etc)
Mazhar
on 15 Aug 2013
Matt J
on 15 Aug 2013
a straight line of length 10 units will fit within these two line with out touching the edges
So it's only the length-10 line segment which must fall between the 2 red lines, correct? If I extrapolate the line segment to infinity at each end, the extrapolated part is allowed to cross the two given red lines?
Mazhar
on 15 Aug 2013
Matt J
on 19 Aug 2013
Do you have the Optimization Toolbox? And will the pipe boundaries always be definable using a function y=f(x)? If the pipe were circular, for example, there would not be an f(x) defining its boundaries.
Mazhar
on 19 Aug 2013
Answers (2)
Image Analyst
on 15 Aug 2013
0 votes
There may be simpler ways, but it looks like SVM (Support Vector Machine) would work. http://en.wikipedia.org/wiki/Support_vector_machine
10 Comments
Mazhar
on 15 Aug 2013
Image Analyst
on 15 Aug 2013
SVM is in the stats toolbox, which I don't have so I can't help you with that since I don't have experience with it.
Mazhar
on 15 Aug 2013
Image Analyst
on 16 Aug 2013
That's correct - there will be no solution in that case. What do you want to do when no line will fit (no matter how you try to solve it)?
Mazhar
on 16 Aug 2013
Image Analyst
on 16 Aug 2013
The "no-fit" case is easy. Just fit a line (via whatever method you want). Then get the coordinates of the line for every x. Then take the top and bottom sides of the points that define the channel and connect them to form a polygon. Then use inpolygon() to determine if a point on the fitted line is outside the polygon.
The "no-fit" case is easy. Just fit a line (via whatever method you want). Then get the coordinates of the line for every x.
Don't think so. That might be an applicable test if the stick going through the pipe were the same length as the pipe. However, if the stick is short enough and the pipe bends gradually enough, the stick will go through no matter how nonlinear the pipe is end-to-end.
Image Analyst
on 16 Aug 2013
I thought it was the same length. If it's not, you'd have to check for every x value just going up to the length of the stick. Like for x elements 1-10, 2-11, 3-12, and so on until you get within 10 of the end. Should be pretty fast though since we're only dealing with small arrays, not megabytes of data.
Mazhar
on 19 Aug 2013
I recommend that you make a binary image of the pipe (e.g., using ROIFILL) and then use HOUGHLINES with the 'MinLength' option to find a segment of (at least) length 10.
11 Comments
Mazhar
on 15 Aug 2013
Matt J
on 15 Aug 2013
Your "bigger result" is a different problem, but I think it's going to require an image processing solution as well.
Mazhar
on 16 Aug 2013
Mazhar
on 16 Aug 2013
I would've thought they're would be a mathematical approach to this??
Don't think so. Not a simple one, anyway.
I definitely think Hough transform analysis would be the simplest path to doing this. With some exploration of the FEX, you might find a Hough transform tool that doesn't require the Image Processing Toolbox. This looks like a possibility
Basically, if a stick of length L fits through the pipe, its Hough Transform image should contain a continuous locus of pixels all of intensity greater than or equal to L.
I would get the Image Processing Toolbox if you can...
Mazhar
on 19 Aug 2013
Matt J
on 19 Aug 2013
I don't think the Hough Transform tools in the Image Processing Toolbox do 3D. There may be alternative ways to do this using Optimization Toolbox functions. That's why I asked you above if you have that toolbox.
Mazhar
on 22 Aug 2013
fminsearch does not do minimization under constraints, which I think you might need in order to constrain the path of the stick to move within the boundaries of the pipe. Algorithms in the Optimization Toolbox will handle constraints and, moreover, are more robustly convergent than fminsearch. That's why I've asked you (3 times now ;)) whether you have the toolbox.
Mazhar
on 22 Aug 2013
Matt J
on 22 Aug 2013
You can set the value of your objective function to Inf for position parameters that put the stick outside the pipe.
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!