public static bool AreSameDirection(Point[] l1, Point[] l2) { var p1 = l1.Concat(l2).ToArray(); var p2 = l1.Concat(l2.Reverse()).ToArray(); var ma1 = TwoLinesMedialAxis.Compute(l1, l2, p1); var ma2 = TwoLinesMedialAxis.Compute(l1, l2, p2); var length1 = ma1.Length >= 2 ? PointsSequenceExtensions.ComputeCurveLength(ma1) : 0; var length2 = ma2.Length >= 2 ? PointsSequenceExtensions.ComputeCurveLength(ma2) : 0; return(length2 > length1); }
public static SubdivisionResult Subdivide(Point[] l1, Point[] l2) { // create a polygon from l1, l2: we assume here that l1 and l2 have the same direction var polygon = l1.Concat(l2.Reverse()).ToArray(); var filteredPoints = TwoLinesMedialAxis.Compute(l1, l2, polygon); // connect the extreme points with a long path (dijkstra algorithm) var proximityDistance = ProximityDistanceEstimate.Compute(filteredPoints); var path = PointsToPolylineConverter.Convert(filteredPoints, proximityDistance); // smooth the path var smoothed = SmoothPath(path); var points = smoothed.Item1; var normals = AverageSmoothNormals(smoothed.Item2); // create the result return(new SubdivisionResult { SpinePoints = points, Normals = normals, }); }