public TrimmedSurface(Surface surface, double angleTolerance = 60) { this.internalSurface = surface; this.curvesByDirections = new Dictionary <Vector, TwoCurves>(); this.tolerance = angleTolerance; // Walk through all perimeter curves foreach (Curve curve in internalSurface.PerimeterCurves()) { // get the curves direction Vector direction = Vector.ByTwoPoints(curve.StartPoint, curve.EndPoint); // If there hasnt been any curve collected add this as the first one if (curvesByDirections.Count == 0) { curvesByDirections.Add(direction, new TwoCurves(curve)); } else { // indicator to check if any curve matches its direction bool matchingOrientation = false; // Walk through all collected curves and check if the direction vectors are // more or less parallel. foreach (Vector vector in curvesByDirections.Keys.ToList()) { if (direction.Parallel(vector, tolerance)) { matchingOrientation = true; // If there is a matching direction already in the dictionary, // Add this curve to the existing curve TwoCurves existingCurve = curvesByDirections[vector]; existingCurve.AddToMatchingCurve(curve); } } // If there is no matching direction, this seems to be a new // Side of the surface if (!matchingOrientation) { curvesByDirections.Add(direction, new TwoCurves(curve)); } } } }
public Curve GetCurveAtParameter(double parameter, bool flip) { // get the orthogonal boundries and the parallel to compare to KeyValuePair <Vector, TwoCurves> data = this.curvesByDirections.First(); TwoCurves compareTo = this.curvesByDirections.Last().Value; // if flip, swap the values if (flip) { data = this.curvesByDirections.Last(); compareTo = this.curvesByDirections.First().Value; } // Get the orthogonal boundaries startpoints Point A = data.Value.Curve1.PointAtParameter(0); Point B = data.Value.Curve2.PointAtParameter(0); Line l = Line.ByStartPointEndPoint(A, B); // Get the desired startpoint Point Async = data.Value.Curve1.PointAtParameter(parameter); // Assuming the other boundary is upside down (other direction than Curve1) // Get the desired endpoint using the inverted parameter // eg. StartParameter = 0.2 therefore the endparameter must be 0.8 // If the curves are pointing in different directions Point Bsync = data.Value.Curve2.PointAtParameter((1 - parameter)); // Check if the assumptin was true, otherwise just use the same // parameter value: StartParam = 0.2 EndParam = 0.2 if (compareTo.AreEndpoints(A, B)) { Bsync = data.Value.Curve2.PointAtParameter(parameter); } // Create the curve for the parameters return(CreateCurve(compareTo, Async, Bsync, parameter, A)); }
private Curve CreateCurve(TwoCurves compareTo, Point A, Point B, double parameter, Point refpoint) { // Init an empty curve Curve returnValue = null; // If the boundaries to compare this curve to are arcs // create a middle line between the boundaries if (compareTo.Curve1.IsArc() || compareTo.Curve2.IsArc()) { Line line = Line.ByStartPointEndPoint(compareTo.Curve1.PointAtParameter(0.5), compareTo.Curve2.PointAtParameter(0.5)); // If the reference point is on curve 2 invert the parameter if (compareTo.Curve1.ClosestPointTo(refpoint).DistanceTo(refpoint) > 0) { parameter = 1 - parameter; } try { // try to create an arc by three points returnValue = Arc.ByThreePoints(A, line.PointAtParameter(parameter), B); } catch (System.ApplicationException) { // On error create a line from A to B returnValue = Line.ByStartPointEndPoint(A, B); } } else { // If the boundaries are lines, create a line from A to B returnValue = Line.ByStartPointEndPoint(A, B); } return(returnValue); }
private Curve CreateCurve(TwoCurves compareTo, Point A, Point B, double parameter, Point refpoint) { // Init an empty curve Curve returnValue = null; // If the boundaries to compare this curve to are arcs // create a middle line between the boundaries if (compareTo.Curve1.IsArc() || compareTo.Curve2.IsArc()) { Line line = Line.ByStartPointEndPoint(compareTo.Curve1.PointAtParameter(0.5), compareTo.Curve2.PointAtParameter(0.5)); // If the reference point is on curve 2 invert the parameter if (compareTo.Curve1.ClosestPointTo(refpoint).DistanceTo(refpoint) > 0) parameter = 1 - parameter; try { // try to create an arc by three points returnValue = Arc.ByThreePoints(A, line.PointAtParameter(parameter), B); } catch (System.ApplicationException) { // On error create a line from A to B returnValue = Line.ByStartPointEndPoint(A, B); } } else // If the boundaries are lines, create a line from A to B returnValue = Line.ByStartPointEndPoint(A, B); return returnValue; }