# How to draw sine curve? • ### Question

• Can i use Path class to draw  the sine curve
I don't know to do archieve....
Thursday, January 11, 2007 9:50 AM

• `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
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
{"ft_lang_label":"__label__en","ft_lang_prob":0.9293079,"math_prob":0.89807856,"size":644,"snap":"2020-34-2020-40","text_gpt3_token_len":146,"char_repetition_ratio":0.1015625,"word_repetition_ratio":0.0,"special_character_ratio":0.19409938,"punctuation_ratio":0.15,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98411655,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-08-11T11:04:08Z\",\"WARC-Record-ID\":\"<urn:uuid:657a8e97-9bef-4c8c-8051-b8cf04911189>\",\"Content-Length\":\"60127\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:e6c93f63-bb7a-4f41-b613-9b21eadf54c2>\",\"WARC-Concurrent-To\":\"<urn:uuid:6aa018eb-53da-4d2b-8121-97c37dc3e999>\",\"WARC-IP-Address\":\"104.117.14.65\",\"WARC-Target-URI\":\"https://social.msdn.microsoft.com/Forums/vstudio/en-US/4875024a-b9a0-4064-9805-2a094c50c3bb/how-to-draw-sine-curve?forum=wpf\",\"WARC-Payload-Digest\":\"sha1:VR4YXYJTE2XCACLVVVST6P6C3UQBV6CJ\",\"WARC-Block-Digest\":\"sha1:B7NFSY3XKGYCUYQZZD3VY7HKNJ2DCAXR\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-34/CC-MAIN-2020-34_segments_1596439738746.41_warc_CC-MAIN-20200811090050-20200811120050-00055.warc.gz\"}"}