Create a spline along points and then extract points at a specified distance apart

6 views (last 30 days)
Hi all,
I have a 3D centreline (XYZ), please see attached .txt. The points are not a equidistant length apart. I want to create a spline along these points and then extract points at a specified distance apart (at every 0.1mm for instance).
Any suggestions welcome.
  3 Comments
HB
HB on 21 Dec 2019
Hi Adam,
Looks like a good function. As far as I can see though it creates points at equidistant intervals along a curve. I don't see where there would be an option to specify the distance (i.e. points that are 0.1mm apart)?
I'm not too familar with matlab lingo so apologies if it is a simple thing!
Adam Danz
Adam Danz on 22 Dec 2019
Edited: Adam Danz on 22 Dec 2019
I see what you mean. Hmmmm. How precise do you need it to be? What if you interpolated it (using the tool I recommended) to a very fine resolution and then accepted the coordinates that were closest to the specified distance apart? You could use that method to resample the 3D curve so that each coordinate interval was n +/- err and the error couuld be very small (with fine interpolation).

Sign in to comment.

Answers (1)

John D'Errico
John D'Errico on 22 Dec 2019
Edited: John D'Errico on 22 Dec 2019
Actually, you CAN use interparc to determine points at a given distance along the curve, with just one extra tool, my arclength utility.
xyz = rand(5,3)
xyz =
0.81472 0.09754 0.15761
0.90579 0.2785 0.97059
0.12699 0.54688 0.95717
0.91338 0.95751 0.48538
0.63236 0.96489 0.80028
5 points along a curve in an R^3 domain. I know, not very creatively chosen. But now, suppose I want to choose points at a uniform distance of 0.1 units along the curve, given a spline interpolant? The trick is to use my arclength utility to determine the total length of the spline curve through those points.
Ltotal = arclength(xyz(:,1),xyz(:,2),xyz(:,3),'spline')
Ltotal =
3.5097
So roughly 3.5 units of distance, measured by following along the curve. Now it is easy to determine a list of points that are equi-distant on the spline, at a uniform spacing of 0.1 from each other.
distlist = (0:0.1:Ltotal)/Ltotal;
xyzhat = interparc(distlist,xyz(:,1),xyz(:,2),xyz(:,3),'spline');
Note that the final point generated will not be exactly the end point, since we insisted on a 0.1 unit spacing along the curve. This is becaue that last point fell at a distance along the curve of 3.5 units, not 3.5097 units.
xyzhat(end,:)
ans =
0.63997 0.96573 0.79427
Finally, note that these points are NOT a uniform distance from each other in the XYZ space.
sqrt(sum(diff(xyzhat,1).^2,2))'
ans =
Columns 1 through 11
0.099991 0.099985 0.099973 0.099945 0.099874 0.09969 0.099377 0.099382 0.09969 0.099868 0.099937
Columns 12 through 22
0.099965 0.099976 0.099981 0.099982 0.099978 0.099965 0.09992 0.099677 0.097636 0.098086 0.0998
Columns 23 through 33
0.099953 0.099982 0.09999 0.099993 0.099994 0.099991 0.09998 0.099881 0.082871 0.09916 0.099964
Columns 34 through 35
0.099992 0.099997
Again, remember, the distance is measured by tracing along the curve itself, but I think that was what was requested.
You can find both interparc and arclength on the File exchange.
  2 Comments
John D'Errico
John D'Errico on 22 Dec 2019
Yes. The trick was to know how interparc works, and how it can be used along with arclength to get the desired result.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!