Exemple #1
0
        private float CalcY(float x)
        {
            int rightIndex = FindRightIndex(x);

            GPoint left  = pointList[rightIndex - 1];
            GPoint right = pointList[rightIndex];

            return(BSpline2D.Bezier3_X2Y(x, left.points[1].Value, left.points[2].Value, right.points[0].Value, right.points[1].Value, MaxLoopCount));
        }
        /// <summary>
        /// Returns the projected curve. The curve "toProject" goes in direction of v, i.e. for each v there is
        /// a value for u. It starts at v=0.0 and ends at v=1.0 - or reverse. The curve "toSweep" of this surface must be planar.
        /// </summary>
        /// <param name="toProject"></param>
        /// <returns></returns>
        internal ICurve2D GetProjectedCurveAlongV(ICurve toProject)
        {
            int n = 8;
            List <GeoPoint2D> pnts = new List <GeoPoint2D>();
            ModOp             m;
            ICurve            swept;

            for (int i = 1; i < n - 1; i++)
            {
                double v = (double)i / (n - 1);
                m     = modOpAt(v);
                swept = toSweep.CloneModified(m);
                double[] ips = toProject.GetPlaneIntersection(swept.GetPlane());
                // eigentlich muss es immer genau einen Schnittpunkt geben
                for (int j = 0; j < ips.Length; j++)
                {
                    if (ips[j] > -1e-6 && ips[j] < 1 + 1e-6)
                    {
                        GeoPoint p = toProject.PointAt(ips[j]);
                        double   u = swept.PositionOf(p);
                        pnts.Add(new GeoPoint2D(u, v));
                        break;
                    }
                }
            }
            m     = modOpAt(0);
            swept = toSweep.CloneModified(m);
            Plane pln     = swept.GetPlane();
            bool  forward = pln.Distance(toProject.StartPoint) < pln.Distance(toProject.EndPoint);

            if (forward)
            {
                pnts.Insert(0, new GeoPoint2D(swept.PositionOf(toProject.StartPoint), 0));
            }
            else
            {
                pnts.Insert(0, new GeoPoint2D(swept.PositionOf(toProject.EndPoint), 0));
            }
            m     = modOpAt(1);
            swept = toSweep.CloneModified(m);
            if (forward)
            {
                pnts.Add(new GeoPoint2D(swept.PositionOf(toProject.EndPoint), 1));
            }
            else
            {
                pnts.Add(new GeoPoint2D(swept.PositionOf(toProject.StartPoint), 1));
            }
            BSpline2D res = new BSpline2D(pnts.ToArray(), 3, false);

            // hier noch Genauigkeit testen und ggf. verfeinern
            if ((PointAt(res.StartPoint) | toProject.StartPoint) + (PointAt(res.EndPoint) | toProject.EndPoint) > (PointAt(res.StartPoint) | toProject.EndPoint) + (PointAt(res.EndPoint) | toProject.StartPoint))
            {
                res.Reverse();
            }
            return(res);
        }
 /// <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));
 }
Exemple #4
0
        /// <summary>
        /// Overrides <see cref="CADability.Curve2D.GeneralCurve2D.Intersect (ICurve2D)"/>
        /// </summary>
        /// <param name="IntersectWith"></param>
        /// <returns></returns>
        public override GeoPoint2DWithParameter[] Intersect(ICurve2D IntersectWith)
        {   // gesucht sind alle Schnittpunkte, also auch in der Verlängerung!
            Line2D l2d = IntersectWith as Line2D;

            if (l2d != null)
            {
                GeoPoint2D ip;
                if (Geometry.IntersectLL(startPoint, endPoint, l2d.StartPoint, l2d.EndPoint, out ip))
                {
                    double pos1 = this.PositionOf(ip);
                    double pos2 = l2d.PositionOf(ip);
                    GeoPoint2DWithParameter pwp = new GeoPoint2DWithParameter();
                    pwp.p    = ip;
                    pwp.par1 = pos1;
                    pwp.par2 = pos2;
                    return(new GeoPoint2DWithParameter[] { pwp });
                }
                else
                {
                    return(new GeoPoint2DWithParameter[0]);
                }
            }
            Circle2D c2d = IntersectWith as Circle2D;

            if (c2d != null)
            {
                GeoPoint2D[] isp = Geometry.IntersectLC(startPoint, endPoint, c2d.Center, c2d.Radius);
                GeoPoint2DWithParameter[] res = new GeoPoint2DWithParameter[isp.Length];
                for (int i = 0; i < isp.Length; ++i)
                {
                    res[i].p    = isp[i];
                    res[i].par1 = this.PositionOf(isp[i]);
                    res[i].par2 = c2d.PositionOf(isp[i]);
                }
                return(res);
            }
            Ellipse2D e2d = IntersectWith as Ellipse2D;

            if (e2d != null)
            {
                GeoPoint2D[] isp = Geometry.IntersectEL(e2d.center, e2d.majorAxis.Length, e2d.minorAxis.Length, e2d.majorAxis.Angle, startPoint, endPoint);
                GeoPoint2DWithParameter[] res = new GeoPoint2DWithParameter[isp.Length];
                for (int i = 0; i < isp.Length; ++i)
                {
                    res[i].p    = isp[i];
                    res[i].par1 = this.PositionOf(isp[i]);
                    res[i].par2 = e2d.PositionOf(isp[i]);
                }
                return(res);
            }
            Polyline2D p2d = IntersectWith as Polyline2D;

            if (p2d != null)
            {
                GeoPoint2DWithParameter[] res = p2d.Intersect(this); // sorum geht es
                for (int i = 0; i < res.Length; ++i)
                {
                    double t = res[i].par1;
                    res[i].par1 = res[i].par2;
                    res[i].par2 = t;
                }
                return(res);
            }
            Path2D pa2d = IntersectWith as Path2D;

            if (pa2d != null)
            {
                GeoPoint2DWithParameter[] res = pa2d.Intersect(this); // sorum geht es
                for (int i = 0; i < res.Length; ++i)
                {
                    double t = res[i].par1;
                    res[i].par1 = res[i].par2;
                    res[i].par2 = t;
                }
                return(res);
            }
            BSpline2D b2d = IntersectWith as BSpline2D;

            if (b2d != null)
            {
                GeoPoint2DWithParameter[] res = b2d.Intersect(this); // sorum geht es
                for (int i = 0; i < res.Length; ++i)
                {
                    double t = res[i].par1;
                    res[i].par1 = res[i].par2;
                    res[i].par2 = t;
                }
                return(res);
            }
            return(base.Intersect(IntersectWith));
        }