作者:JasonXie | 来源:互联网 | 2023-12-11 18:14
IamtryingtodrawpolarcurvesonHTMLcanvasusingJavascript.WhatshouldIdowhenIwanttoco
I am trying to draw polar curves on HTML canvas using Javascript. What should I do when I want to convert plus-minus sign (±)
?
我试图使用Javascript在HTML画布上绘制极坐标曲线。当我想转换加号 - 减号(±)时,我该怎么办?
Example: Watt's curve
示例:瓦特的曲线
Below is what I tried. Since I need to get value of r
, I enclose entire equation with square root, also I use it's absolute value, otherwise I get null
for trying to get square root if number is negative. Following code draws something that looks like a polar curve, but not Watt's curve.
以下是我的尝试。因为我需要获得r的值,所以我用方根包含整个方程式,我也使用它的绝对值,否则如果数字为负则我得到null以获得平方根。下面的代码绘制的东西看起来像极地曲线,但不是瓦特的曲线。
var a = 1;
var b = 1;
var c = 2;
r = Math.sqrt(Math.abs(Math.pow(b, 2) - Math.pow(a * Math.sin(t) * Math.sqrt(Math.abs(Math.pow(c, 2) - Math.pow(a, 2) * Math.pow(Math.cos(t), 2), 2)), 2) ));
I get similar deviations of expected results with other equations containing plus-minus sign (ones without it work fine), so I suppose the problem is that I wrongly 'translate' this symbol. What do I do wrong?
我得到类似的预期结果偏差与其他包含正负号的方程式(没有它的方法工作正常),所以我想问题是我错误地“翻译”了这个符号。我做错了什么?
1 个解决方案