JavaScript Math.sin and Math.cos return wrong values -
this question has answer here:
- is floating point math broken? 20 answers
- javascript math.cos , math.sin inaccurate. there solution? 2 answers
i'm developing simple application math teacher teach trigonometry. application nothing circle angle keeps spinning , shows variation of sin , cos. simple hell.
this have far:

and want achieve

(notice green part representing cos).
everything being built through css. needed calculate height , width of green triangle display it, tought simple calculating sin , cos , multiplying 200(my circle radius in px). reason js giving me inaccurate values sin , cos. example, gives right values if angle 0(cos: 1, sen: 0). if use angle 90, not return right values, shows screenshot below:

this code far(reduced readability)
function trig() { [...] this.radianmultiplier = math.pi / 180; this.setdegree = function(degree) { [...] $('#h').html( math.sin(degree * this.radianmultiplier) ); $('#w').html( math.cos(degree * this.radianmultiplier) ); } } any thoughts on might happening?
Comments
Post a Comment