public ConstrBSplinePoints() { points = new ArrayList(); bSpline = BSpline.Construct(); bSpline.ShowPoints(true, false); closed = false; degree = 3; // könnte auch über einen IntInput gesetzt werden degree = Settings.GlobalSettings.GetIntValue("Constr.BSpline.Degree", 3); }
/// <summary> /// Overrides <see cref="CADability.GeoObject.ISurfaceImpl.Make3dCurve (ICurve2D)"/> /// </summary> /// <param name="curve2d"></param> /// <returns></returns> public override ICurve Make3dCurve(ICurve2D curve2d) { if (curve2d is Curve2DAspect) { ICurve res = (curve2d as Curve2DAspect).Get3DCurve(this); if (res != null) { return(res); } } if (curve2d is ProjectedCurve pc) { if (pc.Surface is SurfaceOfLinearExtrusion) { BoundingRect otherBounds = new BoundingRect(PositionOf(pc.Surface.PointAt(pc.StartPoint)), PositionOf(pc.Surface.PointAt(pc.EndPoint))); if (pc.Surface.SameGeometry(pc.GetExtent(), this, otherBounds, Precision.eps, out ModOp2D notneeded)) { return(pc.Curve3DFromParams); // if trimmed or reversed still returns the correct 3d curve (but trimmed and/or reversed) } } } if (curve2d is Line2D) { Line2D l2d = curve2d as Line2D; GeoVector2D dir = l2d.EndPoint - l2d.StartPoint; if (Math.Abs(dir.x) < Precision.eps) { // das Ergebnis ist eine Mantel-Linie Line res = Line.Construct(); res.StartPoint = PointAt(l2d.StartPoint); res.EndPoint = PointAt(l2d.EndPoint); return(res); } else if (Math.Abs(dir.y) < Precision.eps) { // Basiskurve bzw. Abschnitt derselben ModOp move = ModOp.Translate(l2d.StartPoint.y * direction); ICurve res = basisCurve.CloneModified(move); double sp = (l2d.StartPoint.x - curveStartParameter) / (curveEndParameter - curveStartParameter); double ep = (l2d.EndPoint.x - curveStartParameter) / (curveEndParameter - curveStartParameter); //double sp = l2d.StartPoint.x; //double ep = l2d.EndPoint.x; if (!(basisCurve is BSpline)) { // hier geht auch Verlängern if (sp > ep) { res.Reverse(); if (ep != 0.0 || sp != 1.0) { res.Trim(1.0 - sp, 1.0 - ep); } } else { if (sp != 0.0 || ep != 1.0) { res.Trim(sp, ep); } } } else { if (sp > 1.0 && ep > 1.0) { return(null); } if (sp < 0.0 && ep < 0.0) { return(null); } if (sp > ep) { res.Reverse(); if (ep != 0.0 || sp != 1.0) { res.Trim(1.0 - sp, 1.0 - ep); } } else { if (sp != 0.0 || ep != 1.0) { res.Trim(sp, ep); } } } return(res); } } if (curve2d is BSpline2D) { BSpline2D b2d = (curve2d as BSpline2D); int numpts = b2d.Poles.Length * b2d.Degree; GeoPoint[] pts = new GeoPoint[numpts + 1]; for (int i = 0; i <= numpts; ++i) { pts[i] = PointAt(b2d.PointAt((double)i / (double)numpts)); } BSpline b3d = BSpline.Construct(); b3d.ThroughPoints(pts, b2d.Degree, false); return(b3d); } return(base.Make3dCurve(curve2d)); }
public override ICurve Make3dCurve(ICurve2D curve2d) { if (curve2d is Line2D l2d) { if (Math.Abs(Geometry.DistPL(GeoPoint2D.Origin, l2d.StartPoint, l2d.EndPoint)) < Precision.eps) { double p0 = l2d.PositionOf(GeoPoint2D.Origin); if (p0 > 1e-6 && p0 < 1 - 1e-6) { // the line passes through the apex: we have to split this edge and make a polyline return(Polyline.FromPoints(new GeoPoint[] { PointAt(l2d.StartPoint), location, PointAt(l2d.EndPoint) })); } else { return(Line.TwoPoints(PointAt(l2d.StartPoint), PointAt(l2d.EndPoint))); } } else { // the result is a parabola, which is exactly represented by a BSpline of degree 2 with 3 poles BSpline parabola = BSpline.Construct(); parabola.ThroughPoints(new GeoPoint[] { PointAt(l2d.StartPoint), PointAt(l2d.PointAt(0.5)), PointAt(l2d.EndPoint) }, 2, false); return(parabola); } } else if (curve2d is Ellipse2D elli2d) { // includes EllipseArc2D // this is an ellipse in 3d GeoPoint[] fp3d = new GeoPoint[5]; double n = 5.0; if (elli2d is EllipseArc2D) { n = 4.0; } for (int i = 0; i < 5; i++) { fp3d[i] = PointAt(elli2d.PointAt(i / n)); } Ellipse elli = Ellipse.FromFivePoints(fp3d, !(elli2d is EllipseArc2D)); if (elli != null) { return(elli); } } else if (curve2d is Circle2D circle2d) { // includes Arc2D if (Precision.IsEqual(circle2d.Center, GeoPoint2D.Origin)) { // this is an ellipse in 3d GeoPoint[] fp3d = new GeoPoint[5]; double n = 5.0; if (circle2d is Arc2D) { n = 4.0; } for (int i = 0; i < 5; i++) { fp3d[i] = PointAt(circle2d.PointAt(i / n)); } Ellipse elli = Ellipse.FromFivePoints(fp3d, !(circle2d is Arc2D)); if (elli != null) { return(elli); } } } return(base.Make3dCurve(curve2d)); }