Reputation: 341
I'm working on some JavaScript and I've run across a problem with the math:
var p1 = {x:0,y:0}, p2 = {x:1,y:1};
return Math.sin(45) * Math.sqrt((Math.pow(p2.x-p1.x,2) + Math.pow(p2.y-p1.y,2)));
Returns 1.203359304667218
But when I do the same calculation on my calculator, it returns 1 which is what I expect this calculation to return. Can anyone explain this?
Upvotes: 2
Views: 1076
Reputation: 38052
These are always useful and will likely avoid future confusion:
function sind(d) {
return Math.sin(Math.PI*d/180.0);
}
function cosd(d) {
return Math.cos(Math.PI*d/180.0);
}
function tand(d) {
return Math.tan(Math.PI*d/180.0);
}
Upvotes: 3
Reputation: 30473
var degreesToRadians = function (d) {
return Math.PI * d / 180;
}
Upvotes: 2
Reputation: 2613
What mode did you work on with calculator?
Radians or Degrees? Guess that could be your "problem" which may be solved easily :-)
Upvotes: 3