热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Javascript中带有加号-减号(±)的极坐标曲线方程-Polarcurveequationwithplus-minussign(±)inJavascript

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

示例:瓦特的曲线

Math representation of 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 个解决方案

#1


2  

It looks like there is an incorrect multiplication of a squared theta with the inner square root (Math.sin(t) * Math.sqrt(...)).

看起来平方θ与内平方根(Math.sin(t)* Math.sqrt(...))的乘法不正确。

To plot the equation, convert the plus-minus sign into two equations:

要绘制等式,请将正负号转换为两个等式:

var a = 1;
var b = 1;
var c = 2;

var b2 = Math.pow(b, 2);
var asint = a * Math.sin(t);
var sqroot = Math.sqrt(Math.pow(c, 2) - Math.pow(a, 2) * Math.pow(Math.cos(t), 2), 2);

var r = Math.sqrt(b2 - Math.pow(asint + sqroot, 2));
// now plot r
r = Math.sqrt(b2 - Math.pow(asint - sqroot, 2));
// now plot r again

The Math.abs() shouldn't be necessary.

Math.abs()不应该是必需的。


推荐阅读
author-avatar
JasonXie
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有