我输入了这个:
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 绘制了它:
如何解决?
最佳答案
这是因为
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/