Locate a 3D line given the spatial relationships with other known lines - computer-vision

I am trying to locate a 3D line with the spatial relationships with other known lines. I would like to formulate it as an optimization problem (or an alternative method), but I got stuck with it. Here is the problem statement. Suppose I have at least two known lines l1 and l2, and the target line is lt. I know some spatial relationships between each known line and the target line: 1) distance, 2)the position of perpendicular foot on the known line, and 3) the relative angle. Here is the graph illustration:
My question is:
Is there any similar problems and solutions I can refer to?
Do you have any suggestions on the 3D line representation (e.g., plucker coordinates)?
Thanks in advance for your help.

Related

Polygon Detection from a Set of Lines?

I have a set of connected, intersecting line segments. I want to detect all polygons that result from the intersection of these line segments, as follows:
I found a paper that presents an algorithm for solving this problem, but I'm not really a computer science person so I wasn't able to understand it. Here's a link to the paper. At this moment, my plan is to 1) find all intersections, and 2) somehow use these intersections to identify the polygons. I'm able to solve (1) through brute force, but (2) is a bit trickier. I'd prefer a solution in R or C++, but any language will do.
Assuming you have your line segments always as a closed polygonal chain and you have them in some sort of edge list. And, as you said, you have the intersection points already computed (brute force means O(n^2) time, in this case that is optimal as the line segments can intersect n^2 times).
You can insert your intersection points from (1) into this list splitting the intersecting line segments, mark them as intersection points and reference to all intersecting line segments in this point. Furthermore, on every line segment two polygons are incident, thus add respective reference fields to every edge. Then just take the leftmost vertex in you input and walk along the edge list. Add to every edge that is traversed a reference to its left incident polygon (in this case) polygon number one. If you reach an intersection point, put it on some sort of stack for later recovery. Now analyse that point and continue walking on the leftmost path (between the line segment on which you reached the intersection point and all outgoing segments). At some point you reach your starting point and you have the first simple polygon closed.
Now take the first intersection point from the stack. There must be an even number of line segments that start/end there. Find a line segment that has at most one incident polygon referenced (yet) and use it as as starting segment for polygon number two. You can walk along its chain in the same manner as before. (If you reference a line segment`s right incident polygon, take the rightmost turn on an intersection point.) When your stack ist empty your are done.
Edit: After I looked one more time for a solution I found this implementation from Dan Sunday. I assume that is more useful as it is also already implemented.
Alfredo Ferreira developed c++ code for detecting polygons from a set of overlapping lines. You can find the code at his page here: http://3dorus.ist.utl.pt/tools/PolygonDetector.html
Hope this Helps
I just published my implementation which is extremely fast after trying the algo from the paper.
The basic idea is to remove the detected cycles and redo the search (remove the “ears” of the detected cycle).
I am also unsing just the line segments that have connected points to the graph. The overlapping are removed in two steps: by using the area formula, which is pretty much exact and then approximate the intersection points difference in a specific range.
https://github.com/realuptime/PolyDetector

Intersection of polygon and line segment with intersected polygon side information

I am trying to get intersection of a polygon and a line segment. I can see that I can easily solve this problem with boost geometry.
Though , I need one more information while computing the intersection , I need to know which of the polygon side intersected the line segment. Can anyone suggest me an easy way to get this information?...
Many thanks
Avanindra
Break your polygon into line segments, and intersect each one individually.
Easily? Well, maybe not easily.
Have you looked into binary space partitioning (BSP) trees?
http://en.wikipedia.org/wiki/Binary_space_partitioning
As a rule, if you want theory and code for computational geometry problems, consider looking first at the Geometric Tools website, or the book co-author by the website creator:
http://www.geometrictools.com/SampleMathematics/Boolean2D/Boolean2DBody.html
There are other good textbooks on computational geometry, but Schneider & Eberly is my go-to book.

RANSAC line3d fitting by 3d line segments

I am having many 3d line segments. some of them are nearly parallel
and some are oriented in to different direction. I want to avoid
outliers and to get the best line 3d to represent the given 3d line
segments.
I am bit confused how RANSAC method apply for this case...
should i find a random line first or should i consider this as a given 3d point problem.?
can anyone post me the stucture to be followed when implenting this in c++. thanks
RANSAC is a good tool to fit data to a model. If you had a single 3D line in a collection of segments, by running RANSAC and selecting the line that maximized the amount of inliers would be enough. However, since you have many lines in the collection, you should try a different approach (even a non-RANSAC one, as I tell you later).
For example, you can run first RANSAC trying to find the line that matches as many segments as possible. After finding that line, remove the inlier segments from the collection and run RANSAC again.
To create a line, you only need a segment, so building the line model is quite easy.
To decide on whether a segment fits a line, you may compute the angle between both with the dot product (the closer to 0 the better) and the distance from the middle point of the segment to the line.
Also note that you can filter out very small segments at as first step. You could save some iterations later and avoid noisy results.
I can think of a Hough transform approach as well. Since you can create a line from each segment, you can get the parameters of its line (normal or directional vector and distance to origin), quantize them to some acceptable bin-size and add a vote to those parameters in a matrix. Finally, your lines lie in the peaks of the vote matrix.

matching line segments - robust and fast way

I have 2D line segments extracted from a single image data and would like to match with 3D line segments extracted from other source. for that, first I would like to project a 3D line segment to the image space using co-linearity equation (I know exterior orientation parameters). AS both line segments are in same coordinate system now I would like to find the best matching line segment to that line.
I am looking for a fast and robust algorithm to match corresponding line segments in order to update my 3D line segments later.
If any one have an idea on this, please give some suggestions. thanks in advance.
You're looking at a problem similar to line segment intersection. So unsuprisingly, it's solutions are probably similar as well.
The straightforward approach would be to compare each 2D segment to each 3D segment, best match is the one that most closely corresponds to the predicted length and position when compared to the actual. The actual being the 2D segments. That's something like O(AB), where A is the number of 2D segments and B is the number of 3D segments.
You can speed up the method somewhat by sorting the 2D segments lexicographically, then use the same kind of algorithm I asked about in this question to obtain all line segments whose x values are within a certain amount to the expected x value of one or both of the line segments end point*. In the worst case, you could still run into O(AB), but the average time should be closer to O(B log A). Although, it's not clear as to if you can use this method based on what you've said, so this paragraph should be considered more of an outline.
Faster than O(B log A) or O(A log B) is likely to require this to be a well researched problem.
You can probably get away with 1 end point, if you lexicographically sort the 2D endpoints.

Create smooth line to join N points in 3 dimensions

I have N points in 3-dimensional space. I need to join them using a line. However, if I do that using a simple line, it is not smooth and looks ugly.
My current approach is to use a Bezier curve, using the DeCasteljau algorithm for 4 points, and running that for each group of 4 points in my data set. However, the problem with this is that since I run it on say points 1-4, 5-8, 9-12, etc., separately, the line is not smooth between 4-5, 8-9, etc.
I also looked for other approaches; specifically I found this article about Catmull-Rom splines, which seem even better suited for my purpose, because the curve passes through all control points, unlike the Bezier curve. So I almost started implementing that, but then, I saw on that site that the formula works "assuming uniform spacing of control points". That is not the case for my problem.
So, my question is, what approach should I use -- Bezier, Catmull-Rom, or something completely different? If Bezier, then how to fix the non-smoothness between 4-5, 8-9, etc.? If Catmull-Rom, why won't the formula work if points are not evenly spaced, and what do I need instead?
EDIT: I am now pretty sure I want the Catmull-Rom spline, as it passes every control point which is an advantage for my application. Therefore, the main question I would like answered is why won't the formula on the link I provided work for non-uniformly spaced control points?
Thanks.
A couple of solutions:
Use a B-spline. This is a generalization of Bezier curves (a Bezier curve is a B-spline with no internal knot points.)
Use a cubic spline. Cubic splines are particularly easy to calculate. A cubic spline is continuous in the zero, first, and second derivatives across the control points. The third derivative, the cubic term, suffers a discontinuity at the control points, but it is very hard to see those discontinuities.
One key difference between a B-spline and a cubic spline is that the cubic spline will pass through all of the control points, while a B-spline does not. One way to think about it: Those internal control points are just suggestions for a B-spline but are mandatory for a cubic spline.
A meaningful line (although not the simplest to evaluate) can be found via Gaussian Processes. You set (or infer) the lengthscale over which you wish the line to vary (i.e. the smoothness of the line) and then the GP line is the most probable line through the data given the lengthscale. You can add noise to the model if you don't mind the line not passing through the data points.
Its a nice interpolation method because you can also obtain the standard deviation of your line. The line becomes more uncertain when you don't have much data in the vacinity.
You can read about them in chapter 45 of David MacKay's Information Theory, Inference, and Learning Algorithms - which you can download from the author's website here.
one solution is the following page in wikipedia: http://en.wikipedia.org/wiki/Bézier_curve, check the generalized approach for N control points.