Beispiel #1
0
        public static void TestClosedBspine(string unparsed)
        {
            var dgnModel = Session.Instance.GetActiveDgnModel();
            var uor      = dgnModel.GetModelInfo().UorPerMeter;

            List <DPoint3d> pnts    = new List <DPoint3d>();
            List <double>   degrees = new List <double>()
            {
                0, 45, 90, 135, 180, 225, 270 // 7 个
            };

            foreach (var degree in degrees)
            {
                DPoint3d pnt = new DPoint3d()
                {
                    X = Angle.FromDegrees(degree).Cos *uor,
                    Y = Angle.FromDegrees(degree).Sin *uor,
                    Z = 0,
                };
                pnts.Add(pnt);
            }

            // 节点 = 控制点+2*阶数-1
            List <double> knots = new List <double>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1, 2, 3
            };

            var bspline = BsplineCurve.CreateFromPoles(pnts, knots, 4, true);
            var bknots  = bspline.Knots();

            DraftingElementSchema.ToElement(dgnModel, bspline, null)?.AddToModel();
        }
Beispiel #2
0
        public static void TestOpenCurve(string unparsed)
        {
            var dgnModel = Session.Instance.GetActiveDgnModel();
            var uor      = dgnModel.GetModelInfo().UorPerMeter;

            List <DPoint3d> pnts    = new List <DPoint3d>();
            List <double>   degrees = new List <double>()
            {
                0, 45, 90, 135, 180, 225, 270
            };

            foreach (var degree in degrees)
            {
                pnts.Add(new DPoint3d()
                {
                    X = Angle.FromDegrees(degree).Cos *uor,
                    Y = Angle.FromDegrees(degree).Sin *uor,
                    Z = 0,
                });
            }

            // 节点 = 控制点+阶数
            List <double> knots = new List <double>()
            {
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1
            };

            var bspline = BsplineCurve.CreateFromPoles(pnts, knots, 3, false);

            DraftingElementSchema.ToElement(dgnModel, bspline, null)?.AddToModel();
        }
Beispiel #3
0
        public static void ConeAndBsplineSurface()
        {
            Application app     = Utilities.ComApp;
            Point3d     basePt  = app.Point3dFromXYZ(2, -23, 0);
            Point3d     topPt   = app.Point3dFromXYZ(2, -20, 0);
            Matrix3d    rMatrix = app.Matrix3dFromAxisAndRotationAngle(0, app.Pi() / 6);
            ConeElement oCone   = app.CreateConeElement1(null, 2, ref basePt, 1, ref topPt, ref rMatrix);

            oCone.Color = 0;
            app.ActiveModelReference.AddElement(oCone);

            Point3d[]          aFitPnts  = new Point3d[4];
            InterpolationCurve oFitCurve = new InterpolationCurveClass();

            BsplineCurve[] aCurves = new BsplineCurve[3];

            aFitPnts[0] = app.Point3dFromXYZ(5.9, -21, -0.5);
            aFitPnts[1] = app.Point3dFromXYZ(6.9, -20, 1);
            aFitPnts[2] = app.Point3dFromXYZ(7.9, -20.3, 1.3);
            aFitPnts[3] = app.Point3dFromXYZ(8.9, -20.8, 0.3);
            oFitCurve.SetFitPoints(ref aFitPnts);
            oFitCurve.BesselTangents = true;
            aCurves[0] = new BsplineCurveClass();
            aCurves[0].FromInterpolationCurve(oFitCurve);

            aFitPnts[0] = app.Point3dFromXYZ(6.4, -22, 0);
            aFitPnts[1] = app.Point3dFromXYZ(7.1, -21.2, 0.7);
            aFitPnts[2] = app.Point3dFromXYZ(7.7, -21, 1);
            aFitPnts[3] = app.Point3dFromXYZ(8.4, -21.7, -0.2);
            oFitCurve.SetFitPoints(ref aFitPnts);
            oFitCurve.BesselTangents = true;
            aCurves[1] = new BsplineCurveClass();
            aCurves[1].FromInterpolationCurve(oFitCurve);

            aFitPnts[0] = app.Point3dFromXYZ(5.9, -23, 0);
            aFitPnts[1] = app.Point3dFromXYZ(7.2, -23.1, 1.2);
            aFitPnts[2] = app.Point3dFromXYZ(7.8, -23.3, 0.8);
            aFitPnts[3] = app.Point3dFromXYZ(8.7, -22.8, 0.2);
            oFitCurve.SetFitPoints(ref aFitPnts);
            oFitCurve.BesselTangents = true;
            aCurves[2] = new BsplineCurveClass();
            aCurves[2].FromInterpolationCurve(oFitCurve);

            BsplineSurface oBsplineSurface = new BsplineSurfaceClass();

            oBsplineSurface.FromCrossSections(ref aCurves, MsdBsplineSurfaceDirection.V, 4, true, true);
            BsplineSurfaceElement oSurfaceElm = app.CreateBsplineSurfaceElement1(null, oBsplineSurface);

            oSurfaceElm.Color = 1;
            app.ActiveModelReference.AddElement(oSurfaceElm);
        }
Beispiel #4
0
        public static void TestBspineThroughPnts(string unparsed)
        {
            var dgnModel = Session.Instance.GetActiveDgnModel();
            var uor      = dgnModel.GetModelInfo().UorPerMeter;

            List <DPoint3d> pnts    = new List <DPoint3d>();
            List <double>   degrees = new List <double>()
            {
                0, 45, 90, 135, 180, 225, 270 // 7 个
            };

            foreach (var degree in degrees)
            {
                DPoint3d pnt = new DPoint3d()
                {
                    X = Angle.FromDegrees(degree).Cos *uor,
                    Y = Angle.FromDegrees(degree).Sin *uor,
                    Z = 0,
                };

                // 重复 k 次
                pnts.Add(pnt);
                pnts.Add(pnt);
                pnts.Add(pnt);
            }

            // 节点 = 控制点+阶数
            List <double> knots = new List <double>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24
            };

            var bspline = BsplineCurve.CreateFromPoles(pnts, knots, 3, false);

            DraftingElementSchema.ToElement(dgnModel, bspline, null)?.AddToModel();
        }
Beispiel #5
0
        //-- Biforcation/Branching Solver
        //--
        //--
        private bool BranchSearch(
            BsplineCurve curve,
            double chord,
            ref double param,
            ref Point3d result,
            double tolerance = 0.0001)
        {
            //-- Evaluate Start Point
              //--
              var start = curve.EvaluatePoint( param );

              //-- Search Between [Curve.start, Curve.Max]
              //--
              var min = param;
              var max = 1.0;
              while( ( max - min ) > tolerance )
              {
            //-- Evaluate Mid-Point
            //--
            param = 0.5 * ( min + max );
            result = curve.EvaluatePoint( param );

            //-- Found within Tolerance?
            //--
            var distance = MSApp.Point3dDistance( ref start, ref result );
            if( Math.Abs( distance - chord ) < tolerance ) return true;

            //#debug
            {
              AddLine( start, result );
            }
            //#enddebug

            //-- Select Half-Span
            //--
            if( distance < chord )
              min = param;
            else
              max = param;
              }

              //-- End Point Reached
              //--
              return false;
        }
Beispiel #6
0
        private bool NewtonSearch(
            BsplineCurve curve,
            double chord,
            ref double param,
            ref Point3d result,
            double tolerance = 0.0001)
        {
            //-- Start Point
              //--
              var start = curve.EvaluatePoint( param );

              //-- Initial Guess: Blind Forward
              //--
              param += 0.1;

              while( ( param >= 0.0 ) &&
             ( param <= 1.0 ) )
              {
            //-- Evaluate Point
            //--
            result = curve.EvaluatePoint( param );

            var distance = MSApp.Point3dDistance( ref start, ref result ) - chord;
            if( Math.Abs( distance ) < tolerance ) return true;

            //#debug
            {
              AddLine( start, result );
            }
            //#enddebug

            //-- Newton Raphson Improved Guess
            //-- f'(t) = (f(t+h) - f(t)) / h
            var point = curve.EvaluatePoint( param + tolerance );
            var delta = ( MSApp.Point3dDistance( ref start, ref point ) - ( distance + chord ) ) / tolerance;
            param -= distance / delta;
              }

              return false;
        }
Beispiel #7
0
        //-- Brute force-ish
        //--
        private bool MarchSearch(
            BsplineCurve curve,
            double chord,
            ref double param,
            ref Point3d result,
            double tolerance = 0.0001)
        {
            //-- Evaluate Start Point
              //--
              var start = curve.EvaluatePoint( param );

              //-- Make step size assumption
              //--
              var step = 0.1;

              while( ( param >= 0.0 ) &&
             ( param <= 1.0 ) )
              {
            //-- Next Point
            //--
            param += step;
            result = curve.EvaluatePoint( param );

            //-- Found within Tolerance?
            //--
            var distance = MSApp.Point3dDistance( ref start, ref result );
            if( Math.Abs( distance - chord ) < tolerance ) return true;

            //#debug
            {
              AddLine( start, result );
            }
            //#enddebug

            //-- Overshoot -> Switch Direction + Half Step
            //--
            if( ( ( step > 0 ) && ( distance > chord ) ) ||
            ( ( step < 0 ) && ( distance < chord ) ) )
              step *= -0.5;
              }

              return false;
        }
Beispiel #8
0
        public static void TestBsplineContainsLine(string unparsed)
        {
            var dgnModel = Session.Instance.GetActiveDgnModel();
            var uor      = dgnModel.GetModelInfo().UorPerMeter;

            List <DPoint3d> pnts    = new List <DPoint3d>();
            List <double>   degrees = new List <double>()
            {
                0, 45, 90, 135, 180, 225, 270 // 7 个点
            };

            foreach (var degree in degrees)
            {
                pnts.Add(new DPoint3d()
                {
                    X = Angle.FromDegrees(degree).Cos *uor,
                    Y = Angle.FromDegrees(degree).Sin *uor,
                    Z = 0,
                });
            }

            // 3 阶,则要求有 3 个点共线
            var startPnt = pnts[2];
            var linePnt2 = startPnt - DVector3d.UnitX * uor;
            var linePnt3 = linePnt2 - DVector3d.UnitX * uor;

            // 仅三点共线
            List <DPoint3d> pntsTemp1 = new List <DPoint3d>()
            {
                pnts[0], pnts[1], startPnt, linePnt2, linePnt3
            };

            List <DPoint3d> pntsTemp2 = new List <DPoint3d>()
            {
                pnts[0], pnts[1], startPnt, startPnt, linePnt2, linePnt3, linePnt3
            };

            // 将其它点平移
            for (int i = 3; i < pnts.Count; i++)
            {
                pntsTemp1.Add(pnts[i] - DPoint3d.UnitX * 2 * uor);
                pntsTemp2.Add(pnts[i] - DPoint3d.UnitX * 2 * uor);
            }

            // 节点 = 控制点+阶数
            List <double> knots1 = new List <double>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
            };

            List <double> knots2 = new List <double>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
            };

            var bspline1 = BsplineCurve.CreateFromPoles(pntsTemp1, knots1, 3, false);

            DraftingElementSchema.ToElement(dgnModel, bspline1, null)?.AddToModel();

            // 对第二条曲线平移下
            var          bspline2 = BsplineCurve.CreateFromPoles(pntsTemp2, knots2, 3, false);
            DTransform3d trans    = DTransform3d.FromTranslation(DVector3d.UnitX * 5 * uor);

            bspline2.Transform(trans);
            DraftingElementSchema.ToElement(dgnModel, bspline2, null)?.AddToModel();
        }