c# - OxyPlot 画圆不正确(有间隙)

标签 c# math oxyplot

我输入了这个:

myModel.Series.Add(new FunctionSeries((x) => Math.Sqrt(16 - Math.Pow(x, 2)), -4, 4, 0.1, "x^2 + y^2 = 16") { Color = OxyColors.Red });
myModel.Series.Add(new FunctionSeries((x) => - Math.Sqrt(16 - Math.Pow(x, 2)), -4, 4, 0.1) { Color = OxyColors.Red });

OxyPlot 绘制了它:

enter image description here

如何解决?

最佳答案

这是因为

Math.Sqrt(16 - Math.Pow(x, 2))

对于 x = 4 返回 NaN 因为 16 - Math.Pow(x, 2) 是按 double 计算的。这意味着结果不完全等于 0(在本例中为 -3,5527136788005E-14)。像 Math.Sqrt(-3,5527136788005E-14) 这样的负平方根是未定义的,如 MSDN 中所述。 .

您可以通过禁止负数来修复它。取你计算的最大值和 0 就好

Math.Sqrt(Math.Max(16 - Math.Pow(x, 2), 0))

关于c# - OxyPlot 画圆不正确(有间隙),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47856630/

相关文章:

c# - 事件溯源基础设施实现

c# - 在代码中将 DataTemplate(非 XAML)添加到资源字典?

c# - 如何限定一个类只能在类库项目中使用?

c# - LSODA 到 dll - Fortran (F77) 到 dll 从 C# 调用

c - N 个正方形组成的矩形数量

c# - PlotView 和 Plot 之间有什么不同?

C# 问题读取控制台输出到字符串

math - 激活函数的导数及其在反向传播中的应用

c# - oxyplot items源数据表

c# - 如何更改 OxyPlot Y 轴字符串格式?