使用C#三维图形控件进行曲线曲面分析

使用AnyCAD.Net三维图图形控件能够计算曲线的切线、法线、曲率、长度等,能够计算曲面的uv切线、法线、面积等。

 

代码示例一:曲线分析

复制代码
            Platform.LineStyle lineStyle = new Platform.LineStyle();
            lineStyle.SetLineWidth(0.5f);
            lineStyle.SetColor(ColorValue.BLUE);
            Platform.LineStyle lineStyle2 = new Platform.LineStyle();
            lineStyle2.SetLineWidth(0.5f);
            lineStyle2.SetColor(ColorValue.GREEN);

            Platform.TopoShape arc = renderView.ShapeMaker.MakeEllipseArc(Vector3.ZERO, 100, 50, 45, 270, Vector3.UNIT_Z);
            renderView.ShowGeometry(arc, 100);
 
            {
                Platform.GeomeCurve curve = new Platform.GeomeCurve();
                curve.Initialize(arc);

                float paramStart = curve.FirstParameter();
                float paramEnd = curve.LastParameter();

                float step = (paramEnd - paramStart) * 0.1f;

                for (float uu = paramStart; uu <= paramEnd; uu += step)
                {
                    Vector3 dir = curve.DN(uu, 1);
                    Vector3 pos = curve.Value(uu);

                    // 切线
                    {
                        Platform.TopoShape line = renderView.ShapeMaker.MakeLine(pos, pos + dir);
                        Platform.SceneNode node = renderView.ShowGeometry(line, 101);
                        node.SetLineStyle(lineStyle);
                    }
                    // 法线
                    {
                        Vector3 dirN = dir.CrossProduct(Vector3.UNIT_Z);
                        Platform.TopoShape line = renderView.ShapeMaker.MakeLine(pos, pos + dirN);
                        Platform.SceneNode node = renderView.ShowGeometry(line, 101);
                        node.SetLineStyle(lineStyle2);
                    }

                }

            }
复制代码

 

运行结果:

 

代码示例二:曲面分析

复制代码
            Platform.LineStyle lineStyle = new Platform.LineStyle();
            lineStyle.SetLineWidth(0.5f);
            lineStyle.SetColor(ColorValue.RED);

            TopoShape arc = renderView.ShapeMaker.MakeArc(Vector3.ZERO, 100, -45, 45, Vector3.UNIT_X);
            TopoShape face = renderView.ShapeMaker.Extrude(arc, 200, Vector3.UNIT_X);

            renderView.ShowGeometry(face, 101);

            GeomeSurface surface = new GeomeSurface();
            surface.Initialize(face);
            float ufirst = surface.FirstUParameter();
            float uLarst = surface.LastUParameter();
            float vfirst = surface.FirstVParameter();
            float vLast = surface.LastVParameter();

            float ustep = (uLarst - ufirst) * 0.1f;
            float vstep = (vLast - vfirst) * 0.1f;
            for(float ii=ufirst; ii<=uLarst; ii+= ustep)
                for (float jj = vfirst; jj <= vLast; jj += vstep)
                {
                    Vector3List data = surface.D1(ii, jj);

                    Vector3 pos = data.Get(0);
                    Vector3 dirU = data.Get(1);
                    Vector3 dirV = data.Get(2);
                    Vector3 dir = dirV.CrossProduct(dirU);
                    {
                        Platform.TopoShape line = renderView.ShapeMaker.MakeLine(pos, pos + dir);
                        Platform.SceneNode node = renderView.ShowGeometry(line, 101);

                        node.SetLineStyle(lineStyle);
                    }
                }
复制代码

运行结果

 

 

posted @   AnyCAD  阅读(7586)  评论(0编辑  收藏  举报
编辑推荐:
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
阅读排行:
· 快收藏!一个技巧从此不再搞混缓存穿透和缓存击穿
· Blazor Hybrid适配到HarmonyOS系统
· 支付宝 IoT 设备入门宝典(下)设备经营篇
· 万字调研——AI生成内容检测
· 解决跨域问题的这6种方案,真香!
点击右上角即可分享
微信分享提示