使用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);
                    }
                }

运行结果

 

 

转载于:https://www.cnblogs.com/anycad/p/anycad-csharp-graphics-control-for-curve-surface-analysis.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C#中绘制三维图可以使用.NET Framework提供的Windows Presentation Foundation(WPF)或DirectX技术。 使用WPF,可以使用3D图渲染器在XAML中创建和呈现3D图。以下是一个简单的示例: ```csharp <Window x:Class="Wpf3DGraphics.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <Viewport3D> <Viewport3D.Camera> <PerspectiveCamera Position="0,0,10" LookDirection="0,0,-1" UpDirection="0,1,0" /> </Viewport3D.Camera> <ModelVisual3D> <ModelVisual3D.Content> <Model3DGroup> <AmbientLight Color="#FFFFFF" /> <GeometryModel3D> <GeometryModel3D.Geometry> <MeshGeometry3D Positions="0,1,0 1,-1,0 -1,-1,0" TriangleIndices="0 1 2" /> </GeometryModel3D.Geometry> <GeometryModel3D.Material> <DiffuseMaterial Brush="#FF0000" /> </GeometryModel3D.Material> </GeometryModel3D> </Model3DGroup> </ModelVisual3D.Content> </ModelVisual3D> </Viewport3D> </Grid> </Window> ``` 使用DirectX,可以使用SharpDX库封装DirectX API,以便在C#使用。以下是一个简单的示例: ```csharp using System.Windows.Forms; using SharpDX; using SharpDX.Direct3D9; namespace WinForms3DGraphics { public partial class Form1 : Form { private Device _device; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { PresentParameters presentParameters = new PresentParameters { BackBufferFormat = Format.A8R8G8B8, SwapEffect = SwapEffect.Discard, DeviceWindowHandle = Handle, Windowed = true, BackBufferCount = 1 }; _device = new Device(new Direct3D(), 0, DeviceType.Hardware, Handle, CreateFlags.HardwareVertexProcessing, presentParameters); } private void Form1_Paint(object sender, PaintEventArgs e) { _device.Clear(ClearFlags.Target, new ColorBGRA(0, 0, 255, 255), 1.0f, 0); _device.BeginScene(); // 绘制3D图 _device.EndScene(); _device.Present(); } } } ``` 这里只是简单介绍了两种方法,具体实现取决于您的需求和技术水平。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值