Given a 3D line in CGAL, how do I compute a point on that line that is some known distance from an endpoint?
+2
A:
If you have two points P0 and P1, you can make a vector V = P1 - P0.
Given distance D from P0, you can get the resulting point R = P0 + (D ÷ ||V||) ⋅ V.
(Linearly interpolate between the lines, changing D into a percentage by dividing by the full length of the line.)
I don't know CGAL (and the documentation kind of sucks), but I assume it'd be something like this:
Line_3<K> l = /* ... */;
Vector_3<K> v = l.to_vector();
Point_3<K> r = l.p + (d * d / v.squared_length()) * v;
Note I can't even find a way to get the starting point of a line, so that one is up to you. (The l.p
part is made up.)
GMan
2010-08-17 19:02:51
To get the two points in a line:typedef Kernel::Line_3 Line;Line l = Line(point1, point2);cout << l.point(0) << l.point(1) << "\n";
Max Harris
2010-08-17 20:01:17
@Max: Ah okay. Did the solution work?
GMan
2010-08-17 20:05:16
Well, it won't compile - CGAL doesn't define one of the operators for points and vectors. I don't really know which one, because gcc is the worst compiler known to man. But it's very close, so you get a check :)
Max Harris
2010-08-17 22:31:47
@Max: Ah, if you post the errors I'm sure we could help. (Edit the question, I mean.) And thanks.
GMan
2010-08-17 22:39:10