简体   繁体   English

在WPF中绘制正弦波

[英]Draw Sine Wave in WPF

This one seems quite stupid, but I'm struglling from an hour to do this, 这个看起来很愚蠢,但我从一个小时开始就这样做,

How to Draw the Sine Wave in WPF?? 如何在WPF中绘制正弦波?

Thanks 谢谢

Draw lines between points which you calculate with Math.Sin function. 在使用Math.Sin函数计算的点之间绘制线条。 You'll have to decide how many points per cycle to use, a compromise between drawing speed and accuracy. 您必须决定每个周期使用多少个点,这是绘制速度和精度之间的折衷。 Presumably you'll also need to scale the amplitude to suit the area on the screen, since Sin function will return a value between +1 and -1. 据推测,您还需要缩放幅度以适应屏幕上的区域,因为Sin函数将返回+1和-1之间的值。

How are you doing your "Drawing". 你是如何做“绘画”的。 WPF doesn't have OnPaint events like Winforms so that might prove a little tricky. WPF没有像Winforms这样的OnPaint事件,所以这可能有点棘手。 The way to do this in WinForms would have been to use the Graphics.DrawBezier method 在WinForms中执行此操作的方法是使用Graphics.DrawBezier方法

e.Graphics.DrawBezier(new Pen(new SolidBrush(Color.Red)), 
                          new Point(0, 100), 
                          new Point(50, 0), 
                          new Point(50, 200), 
                          new Point(100, 100));

Maybe that's helpful, but I'm not even sure how to draw directly to the WPF Canvas. 也许这很有帮助,但我甚至不确定如何直接绘制到WPF Canvas。

A quick glance as MSDN shows that it has a BezierSegment control that maybe of use to you. 快速浏览一下,MSDN显示它有一个可能对您有用的BezierSegment控件。

If want curves between your points you can use a PolyBezier to draw your Sine Wave with a PointCollection calculated from the Math.Sin method. 如果想要点之间的曲线,可以使用PolyBezier绘制正弦波,并使用从Math.Sin方法计算的PointCollection。 Alternitavely you could create a lot of BezierSegments which flow on from each other. Alternitavely你可以创建很多BezierSegments,它们互相流动。 Finally just add your PolyBezier or BezierSegments to your form with drawingarea.Children.Add(curve) where drawing area is the grid or canvas you're drawing to. 最后,使用drawingarea.Children.Add(曲线)将PolyBezier或BezierSegments添加到表单中,其中绘图区域是您要绘制的网格或画布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM