简体   繁体   English

如何更好地绘制方程式?

[英]How to draw an equation better?

I have a code that takes an equation and draws it by using points. 我有一个代码,它接受一个方程式并通过使用点将其绘制。 For example, if the equation is y=ax^2+b*x+1 - than I will go over the x's from -100 to 100, find their matching Y value and hold a list of points. 例如,如果等式为y = ax ^ 2 + b * x + 1-则我将遍历x的范围从-100到100,找到它们匹配的Y值并保存点列表。 This is part of my code inside a loop. 这是循环中我的代码的一部分。 My window height is 800 and it's width is 800, so for the point (0,0) I put a small Elipse by setting Canvas.SetTop(e1,400) and Canvas.SetLeft(e1,500) and so on. 我的窗口高度是800,宽度是800,所以对于点(0,0),我通过设置Canvas.SetTop(e1,400)和Canvas.SetLeft(e1,500)等来放置一个小的Elipse。 For each point of the equation I put a small elipse on the Canvas to draw the equation. 对于方程的每个点,我在画布上画了一个小椭圆来画方程。

How can draw the equation better in WPF to get smooth lines, and not a dotted graph? 如何在WPF中更好地绘制方程以获得平滑的线条,而不是虚线图?

 Ellipse E1 = new Ellipse();
 E1.Width = 5;
 E1.Height = 5;
 E1.Fill = Brushes.Black;
 double y;
 y = Exp1;
 y = y / 5;
 x = x / 5;
 x = x + 500.0;
 y = 400.0 - y;
 Canvas.SetTop(E1, y);
 Canvas.SetLeft(E1, x);
 Can1.Children.Add(E1);

You can draw any shape that you need with the Path class . 您可以使用Path绘制所需的任何形状。 That includes a variety of curves that are really quite easy to use, once you know what each parameter is for. 一旦知道每个参数的用途,其中包括各种实际上非常易于使用的曲线。 You can find an introductory article that explains the basics in the Shapes and Basic Drawing in WPF Overview page on MSDN. 您可以在MSDN的“ WPF概述”中的“ 形状和基本图形”中找到介绍性文章,其中介绍了基础知识。 You can find more drawing examples in the first linked page. 您可以在第一个链接的页面中找到更多的绘图示例。

One thing to note is that you'd probably find it a lot easier to define your mathematical symbols using Blend and then use the auto generated XAML, rather than trying to compose it all in C#. 需要注意的一件事是,您可能会发现使用Blend定义数学符号然后使用自动生成的XAML变得容易得多,而不是尝试使用C#编写所有符号。

If you don't want to draw it all yourself, you can find a number of alternative solutions, such as third party libraries and controls, listed in the most popular answer to the How to render a formula in WPF or WinForms question here on StackOverflow. 如果您不想自己绘制所有内容,可以在StackOverflow上的“ 如何在WPF中渲染公式或WinForms”问题的最受欢迎答案中找到许多替代解决方案,例如第三方库和控件。 。

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

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