none
How to draw sine curve? RRS feed

Answers

  • public partial class Window1 : System.Windows.Window
        {
            private Polyline sineCurve;
            public Window1()
            {
                InitializeComponent();
                sineCurve = new Polyline();
                sineCurve.Stroke = Brushes.Red;
                sineCurve.StrokeThickness = 1;
                this.Content = sineCurve;
                AddPoints();
            }
     
            private void AddPoints()
            {
                for (Int32 x = 0; x < 90; x += 1)
                {
                    sineCurve.Points.Add(new Point(x, 50 + 50 * Math.Sin(x / Math.PI)));
                }
            }
        }

    Sheva
    Thursday, January 11, 2007 3:07 PM

All replies

  • public partial class Window1 : System.Windows.Window
        {
            private Polyline sineCurve;
            public Window1()
            {
                InitializeComponent();
                sineCurve = new Polyline();
                sineCurve.Stroke = Brushes.Red;
                sineCurve.StrokeThickness = 1;
                this.Content = sineCurve;
                AddPoints();
            }
     
            private void AddPoints()
            {
                for (Int32 x = 0; x < 90; x += 1)
                {
                    sineCurve.Points.Add(new Point(x, 50 + 50 * Math.Sin(x / Math.PI)));
                }
            }
        }

    Sheva
    Thursday, January 11, 2007 3:07 PM
  • hi Zhou Yong
      thanks for your response.
      I want to draw  a smooth curve.
    And the smoothness which your method drawed depend on the number of point,
    Is there some other method to do it?

     
     
    Friday, January 12, 2007 9:05 AM
  • You could consider drawing the curve using a Catmull-Rom spline or some other interpolating spline (the following wikipedia entry is woefully incomplete, but may get you started in the right direction: http://en.wikipedia.org/wiki/Catmull-Rom_spline). Note, though, that you'll need to convert these to Beziers, as that's the only smooth segment primitive WPF supports.

    Inicidendally, I should point out that internally WPF just flattens "smooth" curves to line-segments. We do it at a resolution, though, that makes it visually indistiguishable from the curve itself. We do have the advantage, though, of knowing the resolution of the display.

     

    Monday, January 15, 2007 6:29 PM