Ejemplo n.º 1
0
        TopoShape CreateShape()
        {
            GPntList v3list = new GPntList();

            double[,] startpiont = new double[1, 3] {
                { 0, 0, 10 }
            };                  //起点
            double length = 10; //波长
            double width  = 4;  //波峰减去波谷差值
            int    nums   = 5;  //支点个数

            double[,] list = GetVerticalCurveList(startpiont, length, width, nums);
            for (int i = 0; i < list.GetLength(0); i++)
            {
                GPnt P0 = new GPnt(list[i, 0], list[i, 1], list[i, 2]);//直井井室入口 起点
                v3list.Add(P0);
            }

            GVec aa  = new GVec(); aa.SetXYZ(v3list[1].XYZ());
            GVec bb  = new GVec(); bb.SetXYZ(v3list[0].XYZ());
            GDir dir = new GDir();

            dir.SetXYZ(aa.Subtracted(bb).XYZ());

            TopoShape section = SketchBuilder.MakeCircle(v3list[0], 0.1, dir);
            TopoShape line9   = SketchBuilder.MakeBSpline(v3list);

            return(FeatureTool.Sweep(section, line9, EnumGeomFillTrihedron.CorrectedFrenet));
        }
        public override void Run(RenderControl render)
        {
            Random   rand   = new Random();
            GPntList points = new GPntList();

            for (int ii = 0; ii < 5; ++ii)
            {
                for (int jj = 0; jj < 5; ++jj)
                {
                    points.Add(new GPnt(ii, jj, rand.NextDouble()));
                }
            }

            var surf = SurfaceBuilder.PointsToBSplineSurface(points, 5);

            var material = MeshStandardMaterial.Create("plastic");

            material.SetRoughness(0.1f);
            material.SetMetalness(0.4f);
            material.SetColor(new Vector3(0.98f, 0.55f, 0.33f));
            material.SetFaceSide(EnumFaceSide.DoubleSide);
            var node = BrepSceneNode.Create(surf, material, null);

            render.ShowSceneNode(node);
        }
        public override void Run(RenderControl render)
        {
            var startPt = new GVec(0, 100, 0);
            var points  = new GPntList();

            points.Add(new GPnt(startPt.XYZ()));
            points.Add(new GPnt(startPt.Added(new GVec(0, 0, 150)).XYZ()));
            points.Add(new GPnt(startPt.Added(new GVec(0, 100, 150)).XYZ()));
            points.Add(new GPnt(startPt.Added(new GVec(-100, 100, 150)).XYZ()));
            points.Add(new GPnt(startPt.Added(new GVec(-100, 300, 150)).XYZ()));
            points.Add(new GPnt(startPt.Added(new GVec(100, 300, 150)).XYZ()));
            TopoShape path = SketchBuilder.MakePolygon(points, false);

            var sectionList = new TopoShapeList();

            GAx2      coord1   = new GAx2(new GPnt(startPt.Added(new GVec(-25, -25, 0)).XYZ()), GP.DY());
            TopoShape section1 = SketchBuilder.MakeRectangle(coord1, 50, 50, 10, false);

            render.ShowShape(section1, Vector3.Red);
            render.ShowShape(path, Vector3.Green);

            TopoShape pipe = FeatureTool.SweepByFrenet(section1, path, EnumSweepTransitionMode.RoundCorner,
                                                       false);

            render.ShowShape(pipe, Vector3.Blue);
        }
        public override void Run(RenderControl render)
        {
            GPntList points = new GPntList();

            points.Add(new GPnt(-100, 0, 0));
            points.Add(new GPnt(100, 0, 0));
            points.Add(new GPnt(0, 100, 0));

            var shape = SketchBuilder.MakePolygon(points, true);

            render.ShowShape(shape, ColorTable.Red);

            var dim1 = new AlignedDimensionNode(new Vector3(-100, 0, 0), new Vector3(0, 100, 0), 20, Vector3.UNIT_Z, "长度");

            dim1.GetMaterial().SetColor(ColorTable.Green);
            dim1.Update();
            render.ShowSceneNode(dim1);

            var dim2 = new LinearDimensionNode(new Vector3(100, 0, 0), new Vector3(0, 100, 0), new Vector3(120, 0, 0), -90, "高度");

            dim2.Update();
            render.ShowSceneNode(dim2);
        }
Ejemplo n.º 5
0
        TopoShape CreateSpline(string fileName)
        {
            using (var sr = new StreamReader(fileName))
            {
                string   line;
                GPntList points = new GPntList();
                while ((line = sr.ReadLine()) != null)
                {
                    var temp = line.Split(',');
                    points.Add(new GPnt(double.Parse(temp[0]), double.Parse(temp[1]), double.Parse(temp[2])));
                }
                if (points.Count > 1)
                {
                    return(SketchBuilder.MakeBSpline(points));
                }
            }

            return(null);
        }
        public override void Run(RenderControl render)
        {
            GPntList points   = new GPntList();
            string   fileName = GetResourcePath("data/CableViewInfo.txt");

            using (StreamReader reader = File.OpenText(fileName))
            {
                while (!reader.EndOfStream)
                {
                    var line  = reader.ReadLine();
                    var items = line.Split(',');
                    if (items.Length < 3)
                    {
                        continue;
                    }

                    double x = double.Parse(items[0]);
                    double y = double.Parse(items[1]);
                    double z = double.Parse(items[2]);

                    points.Add(new GPnt(x, y, z));
                }
            }

            var path = SketchBuilder.MakeBSpline(points);

            render.ShowShape(path, ColorTable.Red);

            var curve = new ParametricCurve(path);
            var rt    = curve.D1(curve.FirstParameter());

            var position = rt.GetPoint();
            var dir      = new GDir(rt.GetVectors()[0]);
            var sketch   = SketchBuilder.MakeCircle(position, 1, dir);
            var pipe     = FeatureTool.Sweep(sketch, path, EnumGeomFillTrihedron.ConstantNormal);

            if (pipe != null)
            {
                render.ShowShape(pipe, new Vector3(0.8f));
            }
        }
        public override void Run(RenderControl render)
        {
            var material = MeshStandardMaterial.Create("metal-double");

            material.SetColor(new Vector3(1.0f, 0.8f, 0.0f));
            material.SetMetalness(0.8f);
            material.SetRoughness(0.5f);
            material.SetFaceSide(EnumFaceSide.DoubleSide);


            var startPt = new GVec(0, 100, 0);
            var points  = new GPntList();

            points.Add(new GPnt(startPt.XYZ()));
            points.Add(new GPnt(startPt.Added(new GVec(0, 0, 150)).XYZ()));
            points.Add(new GPnt(startPt.Added(new GVec(0, 100, 150)).XYZ()));
            points.Add(new GPnt(startPt.Added(new GVec(-100, 100, 150)).XYZ()));
            points.Add(new GPnt(startPt.Added(new GVec(-100, 300, 150)).XYZ()));
            points.Add(new GPnt(startPt.Added(new GVec(100, 300, 150)).XYZ()));
            TopoShape path = SketchBuilder.MakePolygon(points, false);

            var sectionList = new TopoShapeList();

            GAx2      coord1   = new GAx2(new GPnt(startPt.Added(new GVec(-25, -25, 0)).XYZ()), GP.DY());
            TopoShape section1 = SketchBuilder.MakeRectangle(coord1, 50, 50, 10, false);

            render.ShowShape(section1, ColorTable.Red);
            render.ShowShape(path, ColorTable.Green);

            TopoShape pipe = FeatureTool.SweepByFrenet(section1, path, EnumSweepTransitionMode.RoundCorner,
                                                       false);
            BufferShape bs = new BufferShape(pipe, material, null, 0.1f);

            bs.Build();
            var node = new BrepSceneNode(bs);

            render.ShowSceneNode(node);
        }
        public override void Run(RenderControl render)
        {
            double dS           = 19.0;      //弹簧螺距mm
            double dR           = 11.25;     //1/2弹簧中径mm
            double dr1          = 0.9;       //内层钢丝半径mm
            double dr2          = 0.9;       //外层钢丝半径mm
            double dr           = dr1 + dr2; //钢丝轴心分布半径mm
            double da1          = 0.29;      //弹簧螺旋角rad
            double dw0          = 1;         //卷簧轴转速rad/s
            double dw1          = 5;         //拧索轴转速rad/s
            int    nOutterCount = 5;         //外层钢丝股数

            {
                // create the intter path
                GPntList pts = new GPntList();

                for (double t = 0; t < 10; t += 0.1)
                {
                    pts.Add(getIntterMultiSpingCoord(t, dS, dR, dw0));
                }
                var path = SketchBuilder.MakeBSpline(pts);

                // Get the sketch position and direction
                var curve = new ParametricCurve(path);
                var rt    = curve.D1(curve.FirstParameter());

                var position = rt.GetPoint();
                var dir      = new GDir(rt.GetVectors()[0]);
                var sketch   = SketchBuilder.MakeCircle(position, dr1, dir);

                // Create pipe
                var pipe = FeatureTool.Sweep(sketch, path, EnumGeomFillTrihedron.CorrectedFrenet);

                render.ShowShape(pipe, new Vector3(0.8f));
            }


            Vector3[] colors = new Vector3[] { new Vector3(1.0f, 0, 0),
                                               new Vector3(1, 1, 0),
                                               new Vector3(0.5f, 1, 0),
                                               new Vector3(0, 1, 64 / 255.0f),
                                               new Vector3(0, 1, 1) };


            // create the outter path
            for (int i = 0; i < nOutterCount; i++)
            {
                GPntList pts = new GPntList();
                for (double t = 0; t < 10; t += 0.1)
                {
                    pts.Add(getOutterMultiSpingCoord(t, dS, dR, dr, da1, dw0, dw1, i * 2 * Math.PI / nOutterCount));
                }
                var path = SketchBuilder.MakeBSpline(pts);

                // Get the sketch position and direction
                var curve = new ParametricCurve(path);
                var rt    = curve.D1(curve.FirstParameter());

                var position = rt.GetPoint();
                var dir      = new GDir(rt.GetVectors()[0]);

                var sketch = SketchBuilder.MakeCircle(position, dr2, dir);

                // Create pipe
                var pipe = FeatureTool.Sweep(sketch, path, EnumGeomFillTrihedron.CorrectedFrenet);

                render.ShowShape(pipe, colors[i]);
            }
        }
        public override void Run(RenderControl render)
        {
            string filepathp = GetResourcePath(@"data\blade_p.dat");             // p侧字符型数据

            string[] data_p    = File.ReadAllLines(filepathp, Encoding.Default); // 1行    2401列,
            string   filepaths = GetResourcePath(@"data\blade_s.dat");           // s侧字符型数据

            string[] data_s = File.ReadAllLines(filepaths, Encoding.Default);
            //
            // p侧的曲线
            double[,] curvee = new double[(data_p.GetUpperBound(data_p.Rank - 1) + 1), 3]; //建立数组,n行3列,
            for (int i = 0; i < (data_p.GetUpperBound(data_p.Rank - 1) + 1); i++)          //
            {
                data_p[i].Split();
                string[] split = data_p[i].Split(new Char[] { ' ' });
                curvee[i, 0] = double.Parse(split[0]);
                curvee[i, 1] = double.Parse(split[1]);
                curvee[i, 2] = double.Parse(split[2]);
            }
            //
            // s侧的曲线,
            double[,] curvee1 = new double[(data_p.GetUpperBound(data_p.Rank - 1) + 1), 3]; //建立数组,n行3列,
            for (int i = 0; i < (data_p.GetUpperBound(data_p.Rank - 1) + 1); i++)           //
            {
                data_s[i].Split();
                string[] split = data_s[i].Split(new Char[] { ' ' });
                curvee1[i, 0] = double.Parse(split[0]);
                curvee1[i, 1] = double.Parse(split[1]);
                curvee1[i, 2] = double.Parse(split[2]);
            }
            int n_jie    = (int)curvee1[0, 1];          // 截面数
            int n_points = (int)curvee1[0, 0];          // 点数
            // topolist
            TopoShapeList spline = new TopoShapeList(); //进行拓扑list的生成,

            for (int nn = 0; nn < n_jie; nn++)          // 循环截面数,
            {
                //int nn = 0;
                GPntList points = new GPntList();
                // s侧
                for (int mm = nn * n_points + 1; mm < (nn + 1) * n_points; mm++)     // 循环截面所对应的点数范围,
                {
                    GPnt P0 = new GPnt(curvee[mm, 0], curvee[mm, 1], curvee[mm, 2]); //   需要进行添加的点,
                    points.Add(P0);
                }
                // p侧
                for (int mm = (nn + 1) * n_points; mm > nn * n_points + 1; mm--)        // 循环截面所对应的点数范围,
                {
                    GPnt P0 = new GPnt(curvee1[mm, 0], curvee1[mm, 1], curvee1[mm, 2]); //   需要进行添加的点,
                    points.Add(P0);
                }
                // var quxian = SketchBuilder.MakePolygon(points, true);  //生成拓扑,
                var quxian = SketchBuilder.MakeBSpline(points, true);
                //mRenderView.ShowShape(quxian, Vector3.Red);
                spline.Add(quxian);
            }
            var shape = FeatureTool.Loft(spline, true, false);

            //创建一个体进行布尔运算
            GPntList points_shroud = new GPntList();
            GPnt     P10           = new GPnt(170, 0, 0);
            GPnt     P11           = new GPnt(170, 0, 200);
            GPnt     P12           = new GPnt(250, 0, 200);
            GPnt     P13           = new GPnt(250, 0, 0);

            points_shroud.Add(P10);
            points_shroud.Add(P11);
            points_shroud.Add(P12);
            points_shroud.Add(P13);
            var quxian1 = SketchBuilder.MakePolygon(points_shroud, true);
            var face    = SketchBuilder.MakePlanarFace(quxian1);
            var feature = FeatureTool.Revol(face, new GAx1(new GPnt(0, 0, 0), GP.DZ()), 0);

            var cut = BooleanTool.Cut(shape, feature);   // 求差  保留前面的一个

            if (cut != null)
            {
                render.ShowShape(cut, Vector3.Green);
            }

            //var cut2 = BooleanTool.Cut(feature, shape);
            //if (cut2 != null)
            //    render.ShowShape(cut2, Vector3.Blue);
        }