/// <summary> /// Determines the commomn plane of a point and a curve. Returns the common plane in the /// parameter and true if there is such a plane. Returns false, if the point lies not /// in the plane. <seealso cref="Precision"/> /// </summary> /// <param name="p">The point</param> /// <param name="c2">The curve</param> /// <param name="CommonPlane">The common plane</param> /// <returns>true, if there is a common plane, else false</returns> public static bool GetCommonPlane(GeoPoint p, ICurve c2, out Plane CommonPlane) { // kommt erstaunlicherweise ohne Zugriff auf die konkreten Kurven aus PlanarState ps2 = c2.GetPlanarState(); if (ps2 == PlanarState.NonPlanar) { CommonPlane = new Plane(Plane.StandardPlane.XYPlane, 0.0); // braucht leider ein Ergebnis return(false); } if (ps2 == PlanarState.Planar) { Plane p2 = c2.GetPlane(); if (Precision.IsPointOnPlane(p, p2)) { CommonPlane = p2; return(true); } } else { // UnderDetermined, also Linie oder so GeoVector v1 = p - c2.StartPoint; GeoVector v2 = c2.StartDirection; if (!Precision.SameDirection(v1, v2, false) && !Precision.IsNullVector(v1)) { Plane pl = new Plane(p, v1, v2); if (c2.IsInPlane(pl)) { CommonPlane = pl; return(true); } } } CommonPlane = new Plane(Plane.StandardPlane.XYPlane, 0.0); // braucht leider ein Ergebnis return(false); }
/// <summary> /// Determines the common plane of the two curves. If there is a common plane, /// the Parameter CommonPlane gets the result ant the function returns true. Otherwise /// the function returns false. /// </summary> /// <param name="c1">first curve</param> /// <param name="c2">second curve</param> /// <param name="CommonPlane">the resulting common plane</param> /// <returns></returns> public static bool GetCommonPlane(ICurve c1, ICurve c2, out Plane CommonPlane) { // kommt erstaunlicherweise ohne Zugriff auf die konkreten Kurven aus PlanarState ps1 = c1.GetPlanarState(); PlanarState ps2 = c2.GetPlanarState(); if (ps1 == PlanarState.NonPlanar || ps2 == PlanarState.NonPlanar) { CommonPlane = new Plane(Plane.StandardPlane.XYPlane, 0.0); // braucht leider ein Ergebnis return(false); } if (ps1 == PlanarState.Planar) { if (ps2 == PlanarState.Planar) { Plane p1 = c1.GetPlane(); Plane p2 = c2.GetPlane(); if (Precision.IsEqual(p1, p2)) { CommonPlane = p1; return(true); } } else { // ps2 ist UnderDetermined, also einen Punkt mit p1 testen Plane p1 = c1.GetPlane(); if (c2.IsInPlane(p1)) { CommonPlane = p1; return(true); } } } else { // ps1 ist UnderDetermined if (ps2 == PlanarState.Planar) { Plane p2 = c2.GetPlane(); if (c1.IsInPlane(p2)) { CommonPlane = p2; return(true); } } else { // ps1 und ps2 UnderDetermined. Das können nur zwei Linien sein (oder // polylines mit einem Segment oder ähnliches) GeoVector v1 = c1.StartDirection; GeoVector v2 = c2.StartDirection; if (Precision.SameDirection(v1, v2, false)) { // d.h. parallel GeoVector v3 = c2.StartPoint - c1.StartPoint; if (!Precision.SameDirection(v1, v3, false)) { try { CommonPlane = new Plane(c1.StartPoint, v1, v3); return(true); } catch (PlaneException) { CommonPlane = new Plane(Plane.StandardPlane.XYPlane, 0.0); // braucht leider ein Ergebnis return(false); } } // else: colinear, geht also nicht } else { try { Plane p = new Plane(c1.StartPoint, v1, v2); if (c2.IsInPlane(p)) { CommonPlane = p; return(true); } GeoPoint[] pnts = new GeoPoint[4]; pnts[0] = c1.StartPoint; pnts[1] = c1.EndPoint; pnts[2] = c2.StartPoint; pnts[3] = c2.EndPoint; p = Plane.FromPoints(pnts, out double maxDist, out bool isLinear); if (maxDist < Precision.eps) { CommonPlane = p; return(true); } } catch (PlaneException) { CommonPlane = new Plane(Plane.StandardPlane.XYPlane, 0.0); // braucht leider ein Ergebnis return(false); } } } } CommonPlane = new Plane(Plane.StandardPlane.XYPlane, 0.0); // braucht leider ein Ergebnis return(false); }
/// <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 (firstCurve is Line && secondCurve is Line) { if (Precision.IsPerpendicular(firstCurve.StartDirection, pl.Normal, false) && Precision.IsPerpendicular(secondCurve.StartDirection, pl.Normal, false)) { // eine Ebene, die zu beiden Linien parallel ist GeoPoint sp1, ep1, sp2, ep2; sp1 = firstCurve.PointAt(umin); ep1 = secondCurve.PointAt(umin); sp2 = firstCurve.PointAt(umax); ep2 = secondCurve.PointAt(umax); GeoPoint2D[] ip1 = pl.GetLineIntersection(sp1, ep1 - sp1); GeoPoint2D[] ip2 = pl.GetLineIntersection(sp2, ep2 - sp2); if (ip1.Length == 1 && ip2.Length == 1) { GeoPoint sp = pl.PointAt(ip1[0]); GeoPoint ep = pl.PointAt(ip2[0]); double v = Geometry.LinePar(sp1, ep1, sp); Line line = Line.Construct(); line.SetTwoPoints(sp, ep); DualSurfaceCurve dsc = new DualSurfaceCurve(line, this, new Line2D(new GeoPoint2D(umin, v), new GeoPoint2D(umax, v)), pl, new Line2D(ip1[0], ip2[0])); return(new IDualSurfaceCurve[] { dsc }); } } } if (firstCurve is Ellipse && secondCurve is Ellipse) { Ellipse e1 = firstCurve as Ellipse; Ellipse e2 = secondCurve as Ellipse; if (Precision.SameDirection(pl.Normal, e1.Plane.Normal, false) && Precision.SameDirection(pl.Normal, e2.Plane.Normal, false)) { if (e1.IsCircle && e2.IsCircle) { GeoPoint sp1, ep1, sp2, ep2, spm, epm; sp1 = firstCurve.PointAt(umin); ep1 = secondCurve.PointAt(umin); sp2 = firstCurve.PointAt(umax); ep2 = secondCurve.PointAt(umax); spm = firstCurve.PointAt((umin + umax) / 2.0); epm = secondCurve.PointAt((umin + umax) / 2.0); GeoPoint2D[] ip1 = pl.GetLineIntersection(sp1, ep1 - sp1); GeoPoint2D[] ip2 = pl.GetLineIntersection(sp2, ep2 - sp2); GeoPoint2D[] ipm = pl.GetLineIntersection(spm, epm - spm); if (ip1.Length == 1 && ip2.Length == 1 && ipm.Length == 1) { Ellipse e3 = Ellipse.Construct(); e3.SetArc3Points(pl.PointAt(ip1[0]), pl.PointAt(ipm[0]), pl.PointAt(ip2[0]), pl.Plane); double v = Geometry.LinePar(sp1, ep1, pl.PointAt(ip1[0])); DualSurfaceCurve dsc = new DualSurfaceCurve(e3, this, new Line2D(new GeoPoint2D(umin, v), new GeoPoint2D(umax, v)), pl, e3.GetProjectedCurve(pl.Plane)); return(new IDualSurfaceCurve[] { dsc }); } } } } PlanarState ps1 = firstCurve.GetPlanarState(); PlanarState ps2 = secondCurve.GetPlanarState(); if ((ps1 == PlanarState.UnderDetermined || ps1 == PlanarState.Planar) && (ps2 == PlanarState.UnderDetermined || ps2 == PlanarState.Planar)) { if (Precision.IsPerpendicular(firstCurve.StartDirection, pl.Normal, false) && Precision.IsPerpendicular(secondCurve.StartDirection, pl.Normal, false)) { // beide Kurven sind eben und parallel zur Schnittebene, wir haben also ein festes v und somit eine Zwischenkurve GeoPoint ip = pl.Plane.Intersect(firstCurve.StartPoint, secondCurve.StartPoint - firstCurve.StartPoint); double v = Geometry.LinePar(firstCurve.StartPoint, secondCurve.StartPoint, ip); ICurve cv = FixedV(v, umin, umax); DualSurfaceCurve dsc = new DualSurfaceCurve(cv, this, new Line2D(new GeoPoint2D(umin, v), new GeoPoint2D(umax, v)), pl, cv.GetProjectedCurve(pl.Plane)); return(new IDualSurfaceCurve[] { dsc }); } } return(base.GetPlaneIntersection(pl, umin, umax, vmin, vmax, precision)); }