/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Math.cos(x)

Hello,

I am curious:

When I type cos5 into my calculator, I get: 0.996164698

When I type

document.write(Math.cos(5) + ‘<br />’);

I get: 0.28366218546322624 😮

To keep a long story short, I understand that is has to do with radians vs. degrees. I need to find x and y coordinates expressed in pixels using the cosine function.

Is there any way to force javascript to use degress instead of radians? ?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Sup3rkirbyNov 19.2011 — You can't force Javascript to use degrees, however, you can use a little conversion to get the job done.
[CODE]
var iValue = 5;
var c = Math.PI / 180;
Math.cos(c * iValue);
[/CODE]
Copy linkTweet thisAlerts:
@vb2javaauthorNov 19.2011 — Nice,

Thanks Sup3rkirby. I was just about to post that I found the conversion.
×

Success!

Help @vb2java spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...