The order of domain start and end doesnt seem to matter. It trims the polyline from the lower value to higher value.
Any ideas on how to do a cyclical trim?
Hint: A polyline is a list of point, so get the floor and ceils of your domain start and end, split into two lists and interpolate the points in between and append them as first and last points in your new two lists.
@dn.aur
I ended up creating a util method that works for me.
The grasshopper script you attached works similar to Polyline.Trim method from RhinoCommon but thanks for your reply!
Cheers
public static Polyline TrimPeriodicPolyline(Polyline polyline, double trimDomainStart, double trimDomainEnd)
{
if (!polyline.IsClosed) throw new Exception(" Input polyline must be closed.");
var trimmedPolyline = new Polyline();
var firstPoint = polyline.PointAt(trimDomainStart);
trimmedPolyline.Add(firstPoint);
var indexToAppend = Math.Ceiling(trimDomainStart);
while (indexToAppend != Math.Ceiling(trimDomainEnd))
{
trimmedPolyline.Add(polyline.PointAt(indexToAppend));
// cyclical increment for index
indexToAppend = (indexToAppend + 1) % polyline.Count;
}
var lastPoint = polyline.PointAt(trimDomainEnd);
trimmedPolyline.Add(lastPoint);
// tolerance for method can be retrieved from document tolerance
trimmedPolyline.RemoveNearlyEqualSubsequentPoints(1);
return trimmedPolyline;
}