/// <summary> /// Overrides <see cref="CADability.GeoObject.ISurfaceImpl.GetPlaneIntersection (PlaneSurface, double, double, double, double, double)"/> /// </summary> /// <param name="pl"></param> /// <param name="umin"></param> /// <param name="umax"></param> /// <param name="vmin"></param> /// <param name="vmax"></param> /// <param name="precision"></param> /// <returns></returns> public override IDualSurfaceCurve[] GetPlaneIntersection(PlaneSurface pl, double umin, double umax, double vmin, double vmax, double precision) { if (Precision.IsPerpendicular(pl.Plane.Normal, direction, false)) { // Ebene, die parallel zur Auszugsrichtung liegt. Es entstehen Linien List <IDualSurfaceCurve> res = new List <IDualSurfaceCurve>(); double[] cpar = basisCurve.GetPlaneIntersection(pl.Plane); for (int i = 0; i < cpar.Length; i++) { // von 0..1 auf startParameter..endParameter umrechnen double pos = curveStartParameter + cpar[i] * (curveEndParameter - curveStartParameter); if (pos >= umin && pos <= umax) { ICurve c3d = FixedU(pos, vmin, vmax); Line2D l2d = new Line2D(new GeoPoint2D(pos, vmin), new GeoPoint2D(pos, vmax)); DualSurfaceCurve dsc = new DualSurfaceCurve(c3d, this, l2d, pl, c3d.GetProjectedCurve(pl.Plane)); res.Add(dsc); } } return(res.ToArray()); //return new IDualSurfaceCurve[] { }; //return base.GetPlaneIntersection(pl, umin, umax, vmin, vmax, precision); // stürzt ab mit 50050020_012_1_FMZ.stp } else if (Precision.SameDirection(direction, pl.Plane.Normal, false)) { if (basisCurve.GetPlanarState() == PlanarState.Planar && Precision.SameDirection(direction, basisCurve.GetPlane().Normal, false)) { Plane cp = basisCurve.GetPlane(); if (!Precision.SameNotOppositeDirection(cp.Normal, direction)) { cp = new Plane(cp.Location, cp.DirectionY, cp.DirectionX); } double v = cp.Distance(pl.Plane.Location) / direction.Length; Line2D l2d = new Line2D(new GeoPoint2D(curveStartParameter, v), new GeoPoint2D(curveEndParameter, v)); DualSurfaceCurve dsc = new DualSurfaceCurve(basisCurve.CloneModified(ModOp.Translate(v * direction)), this, l2d, pl, basisCurve.GetProjectedCurve(pl.Plane)); return(new IDualSurfaceCurve[] { dsc }); } } // keine Lösung gefunden double[] upos = basisCurve.GetSavePositions(); InterpolatedDualSurfaceCurve.SurfacePoint[] sp = new InterpolatedDualSurfaceCurve.SurfacePoint[upos.Length]; for (int i = 0; i < upos.Length; ++i) { GeoPoint p0 = basisCurve.PointAt(upos[i]); double pos = curveStartParameter + upos[i] * (curveEndParameter - curveStartParameter); GeoPoint2D[] ips = pl.GetLineIntersection(p0, direction); if (ips.Length == 1) { GeoPoint p3d = pl.PointAt(ips[0]); double v = Geometry.LinePar(p0, direction, p3d); sp[i] = new InterpolatedDualSurfaceCurve.SurfacePoint(p3d, new GeoPoint2D(pos, v), ips[0]); } } InterpolatedDualSurfaceCurve idsc = new InterpolatedDualSurfaceCurve(this, pl, sp, true); return(new IDualSurfaceCurve[] { idsc.ToDualSurfaceCurve() }); //return base.GetPlaneIntersection(pl, umin, umax, vmin, vmax, precision); }
public override IDualSurfaceCurve[] GetPlaneIntersection(PlaneSurface pl, double umin, double umax, double vmin, double vmax, double precision) { if (Precision.IsPerpendicular(pl.Normal, zAxis, false)) { // two lines along the cylinder axis Plane lower = new Plane(location, zAxis); GeoPoint2D sp2d = lower.Project(pl.Location); GeoVector2D dir2d = lower.Project(pl.Normal).ToLeft(); GeoPoint2D[] ips = Geometry.IntersectLC(sp2d, dir2d, GeoPoint2D.Origin, xAxis.Length); IDualSurfaceCurve[] res = new IDualSurfaceCurve[ips.Length]; for (int i = 0; i < ips.Length; i++) { GeoPoint p = lower.ToGlobal(ips[i]); Line l3d = Line.TwoPoints(p, p + zAxis); res[i] = new DualSurfaceCurve(l3d, this, new Line2D(this.PositionOf(l3d.StartPoint), this.PositionOf(l3d.EndPoint)), pl, new Line2D(pl.PositionOf(l3d.StartPoint), pl.PositionOf(l3d.EndPoint))); } return(res); } else { // an ellipse GeoPoint2D[] cnts = pl.GetLineIntersection(location, zAxis); if (cnts.Length == 1) { // there must be exactly one intersection GeoPoint cnt = pl.PointAt(cnts[0]); GeoVector minorAxis = pl.Normal ^ zAxis; minorAxis.Length = xAxis.Length; GeoVector majorAxis = minorAxis ^ pl.Normal; Polynom impl = GetImplicitPolynomial(); Polynom toSolve = impl.Substitute(new Polynom(majorAxis.x, "u", cnt.x, ""), new Polynom(majorAxis.y, "u", cnt.y, ""), new Polynom(majorAxis.z, "u", cnt.z, "")); double[] roots = toSolve.Roots(); // there must be two roots majorAxis = roots[0] * majorAxis; Ellipse elli = Ellipse.Construct(); elli.SetEllipseCenterAxis(cnt, majorAxis, minorAxis); GeoPoint2D[] fpnts = new GeoPoint2D[5]; for (int i = 0; i < 5; i++) { fpnts[i] = PositionOf(elli.PointAt(i / 6.0)); } Ellipse2D e2d = Ellipse2D.FromFivePoints(fpnts); // there should be a better way to calculate the 2d ellipse, but the following is wrong: // Ellipse2D e2d = new Ellipse2D(GeoPoint2D.Origin, PositionOf(cnt + majorAxis).ToVector(), PositionOf(cnt + minorAxis).ToVector()); // and principal axis doesn't yield the correct result either // Geometry.PrincipalAxis(PositionOf(cnt + majorAxis).ToVector(), PositionOf(cnt + minorAxis).ToVector(), out GeoVector2D maj, out GeoVector2D min); return(new IDualSurfaceCurve[] { new DualSurfaceCurve(elli, this, e2d, pl, pl.GetProjectedCurve(elli, 0.0)) }); } } return(new IDualSurfaceCurve[0]); }
/// <summary> /// Overrides <see cref="CADability.GeoObject.ISurfaceImpl.GetPlaneIntersection (PlaneSurface, double, double, double, double, double)"/> /// </summary> /// <param name="pl"></param> /// <param name="umin"></param> /// <param name="umax"></param> /// <param name="vmin"></param> /// <param name="vmax"></param> /// <param name="precision"></param> /// <returns></returns> public override IDualSurfaceCurve[] GetPlaneIntersection(PlaneSurface pl, double umin, double umax, double vmin, double vmax, double precision) { IDualSurfaceCurve[] idsc = base.GetPlaneIntersection(pl, umin, umax, vmin, vmax, precision); if (idsc == null || idsc.Length == 0) { return(idsc); } IDualSurfaceCurve dsc = idsc[0]; if (dsc != null) { dsc = new DualSurfaceCurve(dsc.Curve3D, this, new ProjectedCurve(dsc.Curve3D, this, true, new BoundingRect(umin, vmin, umax, vmax)), dsc.Surface2, dsc.Curve2D2); } return(new IDualSurfaceCurve[] { dsc }); }