Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在WPF中绘制缓和曲线的示例代码?_C#_Wpf_Wpf Controls - Fatal编程技术网

C# 在WPF中绘制缓和曲线的示例代码?

C# 在WPF中绘制缓和曲线的示例代码?,c#,wpf,wpf-controls,C#,Wpf,Wpf Controls,我在谷歌上搜索,什么也没找到。你知道一些吗?找到了螺旋方程(你必须决定存在哪一种,不同类型的螺旋),也就是说:那一种是用极坐标表示的。因此,您需要近似它,例如通过直线。这就是我要走的路。 因此,我可以发布一些代码作为示例,我在一个scratch new wpf应用程序中编写,并从xaml中删除了默认网格(如果您想尽快测试代码,这是必要的): 公共部分类主窗口:窗口 { 公共主窗口() { 初始化组件(); 路径p=新路径(); p、 Data=CreateSpiralGeometry(1000,

我在谷歌上搜索,什么也没找到。你知道一些吗?

找到了螺旋方程(你必须决定存在哪一种,不同类型的螺旋),也就是说:那一种是用极坐标表示的。因此,您需要近似它,例如通过直线。这就是我要走的路。 因此,我可以发布一些代码作为示例,我在一个scratch new wpf应用程序中编写,并从xaml中删除了默认网格(如果您想尽快测试代码,这是必要的):

公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
路径p=新路径();
p、 Data=CreateSpiralGeometry(1000,新点(){X=200,Y=180},Math.PI*10100);
p、 笔划=画笔。黑色;
AddChild(p);
}
private PathGeometry CreateSpiralGeometry(int nOfSteps、Point startPoint、double tetha、double alpha)
{
路径图螺旋=新路径图();
spiral.StartPoint=起始点;

对于(int i=0;i@user310291,你能在你的问题中包含更多的信息吗,比如你到目前为止尝试了什么,或者你在哪里遇到了困难?你的问题本质上是更数学化的,还是与XAML/WPF更相关?等等。WPF中的示例代码还不够清晰?!关键是人们通常不喜欢将代码交给别人。我们想知道在你已经尝试过的情况下,你的请求只是懒惰。这在常见问题解答中有介绍。我是通过谷歌搜索找到这里的帖子的。海报忽略了为什么这在WPF中不是一个简单的问题,即无法将图像绘制为一组点。这是基于向量的XAML/WPF绘图的副作用。这不是我的懒惰寻找这类解决方案,但这是一个明确的困难。WPF有一个简单的曲线、圆弧、直线等现成的库。但是,不费吹灰之力就很难画出螺旋形状。一种方法是将每个点画成单位长度的线段……剩下的部分我没有空间扩展。我还需要WPF中的代码not-only算法。
 public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Path p = new Path();
            p.Data = CreateSpiralGeometry(1000, new Point() { X = 200, Y = 180 },Math.PI*10, 100);
            p.Stroke = Brushes.Black;

            AddChild(p);
        }

        private PathGeometry CreateSpiralGeometry(int nOfSteps, Point startPoint, double tetha, double alpha)
        {
            PathFigure spiral = new PathFigure();
            spiral.StartPoint = startPoint;


            for(int i=0;i<nOfSteps;++i)
            {
                var t = (tetha/nOfSteps)*i;
                var a = (alpha/nOfSteps)*i;
                Point to = new Point(){X=startPoint.X+a*Math.Cos(t), Y=startPoint.Y+a*Math.Sin(t)};
                spiral.Segments.Add(new LineSegment(to,true));
            }
            return new PathGeometry(new PathFigure[]{ spiral});
        }



    }