geom.resample
drafting: Q = geom.resample (P, N)
drafting: Q = geom.resample (P, 'spacing', D)
drafting: Q = geom.resample (…, CLOSED)
drafting: [Q, S] = geom.resample (…)
Respace the points of a curve evenly along its length.
Q = geom.resample (P, N) returns N points
spaced equally along the polyline P, the first at its start and the
last at its end.
Q = geom.resample (P, spaces
them D apart instead, taking as many as fit. The last point lands at
the end of the curve whatever the remainder, so the final gap may be shorter
than D; a curve is not lengthened to make the arithmetic tidy.
'spacing', D)
Adding CLOSED as a final true argument treats the curve as closed, in which case the returned points do not repeat the first.
[Q, S] = geom.resample (…) also returns the distance
along the curve at which each point was taken.
geom.curvesample geom.curvesample samples a curve it can evaluate, refining
where the curvature demands it, and is the right tool when the curve is
known as a function. This one has only the points it is given, so it can
interpolate between them but never recover what fell between two samples.
Use it to give a curve evenly spaced points — for a marker every so many millimetres, for a table of inspection coordinates, for feeding an algorithm that assumes uniform spacing — not to improve one that was sampled too coarsely. Resampling a coarse polyline finely produces a great many points on the same straight lines it already had.
The returned points are new ones, placed at equal distances; the original vertices are not among them unless a sample happens to land on one. Where two samples straddle a corner, the curve between them is the chord, and the corner is gone. The result is therefore slightly shorter than the original and slightly inside it.
That is inherent to spacing points evenly — a corner is exactly the place
where a curve cannot be walked at constant speed and still be reproduced —
but it means a polygon should not be resampled if its vertices
matter. Feature lines, outlines to be cut, and anything with a defined
corner want geom.simplify, which only ever removes points and so can
never invent a chord across one.
See also: geom.curvesample, geom.simplify, geom.arclength
Source Code: geom.resample
Equal spacing along the curve, for a marker every so many millimetres or a table of inspection points.
t = linspace (0, 2*pi, 361)(1:360)';
P = (30 + 5 * cos (6 * t)) .* [cos(t), sin(t)];
Q = geom.resample (P, 24, true);
D = draw.Drawing ().polyline (P, true);
D.Colour = 'red';
for k = 1:rows (Q)
D = D.circle (Q(k,:), 1);
endfor
plot (D);
title ('24 points spaced equally along the profile');
Resampling replaces the original vertices, so a corner between two samples is cut. A polygon whose corners matter wants geom.simplify, which only ever removes points and so can never invent a chord across one.
P = [0, 0; 40, 0; 40, 30];
D = draw.Drawing ().polyline (P);
D.Colour = 'red';
D = D.polyline (geom.resample (P, 6));
plot (D);
title ('the corner is cut when the samples straddle it');