开发者

Sample code for drawing a spiral in WPF? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help cente开发者_如何学Pythonr. Closed 12 years ago.

I searched on Google I found nothing. Do you know some ?


Found the spiral equation ( you have to decide wich one, different kind of spiral exists ) ie: http://mathworld.wolfram.com/ArchimedesSpiral.html that one is presented in polar coordinates. Given so you need to approximate it, for example by lines. This is the way I will go. So I can post some code just as an example, I wrote in a scratch new wpf application,and I removed the default grid from the xaml ( necessary if you want to test soon the code ) :

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



    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜