Ejemplo n.º 1
0
        IDualSurfaceCurve[] IDualSurfaceCurve.Split(double v)
        {
            ICurve[] splitted = curve3D.Split(v);
            if (splitted == null || splitted.Length != 2)
            {
                return(null);
            }
            IDualSurfaceCurve dsc1 = null, dsc2 = null;

            if (curve3D is InterpolatedDualSurfaceCurve)
            {
                dsc1 = new DualSurfaceCurve(splitted[0], surface1, (splitted[0] as InterpolatedDualSurfaceCurve).CurveOnSurface1, surface2, (splitted[0] as InterpolatedDualSurfaceCurve).CurveOnSurface2);
                dsc2 = new DualSurfaceCurve(splitted[1], surface1, (splitted[1] as InterpolatedDualSurfaceCurve).CurveOnSurface1, surface2, (splitted[1] as InterpolatedDualSurfaceCurve).CurveOnSurface2);
            }
            else
            {
                dsc1 = new DualSurfaceCurve(splitted[0], surface1, surface1.GetProjectedCurve(splitted[0], 0.0), surface2, surface2.GetProjectedCurve(splitted[0], 0.0));
                dsc2 = new DualSurfaceCurve(splitted[1], surface1, surface1.GetProjectedCurve(splitted[1], 0.0), surface2, surface2.GetProjectedCurve(splitted[1], 0.0));
            }
            return(new IDualSurfaceCurve[] { dsc1, dsc2 });

            //GeoPoint2D uv1 = surface1.PositionOf(splitted[0].EndPoint);
            //GeoPoint2D uv2 = surface2.PositionOf(splitted[0].EndPoint);
            //double u1 = curve2D1.PositionOf(uv1);
            //double u2 = curve2D2.PositionOf(uv2);

            //GeoVector2D dir12d = curve2D1.DirectionAt(u1);
            //GeoVector2D dir22d = curve2D2.DirectionAt(u2);
            //GeoVector dir1 = dir12d.x*surface1.UDirection(uv1)+ dir12d.y * surface1.VDirection(uv1);
            //GeoVector dir2 = dir22d.x*surface2.UDirection(uv2)+ dir22d.y * surface2.VDirection(uv2);
            //GeoVector dir = curve3D.DirectionAt(v);
            //// dir1 should be in direction of curve3d, dir2 in the opposite dierection
            //if (dir1 * dir < 0) curve2D1.Reverse();
            //if (dir2 * dir > 0) curve2D2.Reverse();
            //ICurve2D[] splitted1 = curve2D1.Split(u1);
            //ICurve2D[] splitted2 = curve2D2.Split(u2);
            //if (splitted1 == null || splitted1.Length != 2) return null;
            //if (splitted2 == null || splitted2.Length != 2) return null;
            //IDualSurfaceCurve dsc1 = null, dsc2 = null;
            //dsc1 = new DualSurfaceCurve(splitted[0], surface1, splitted1[0], surface2, splitted2[1]);
            //dsc2 = new DualSurfaceCurve(splitted[1], surface1, splitted1[1], surface2, splitted2[0]);
            //return new IDualSurfaceCurve[] { dsc1, dsc2 };
        }
Ejemplo n.º 2
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)
        {
            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));
        }