/    Sign up×
Community /Pin to ProfileBookmark

How to calculate angles using trigonometry in javascript?

Hi.
I’ve had a look at the various trigonometry functions: Math.tan() etc.
However I’m a little confused as to how to use them to do what I want.It’s made all the more so by the fact that they deal with ‘radians’ rather than ‘degrees’!

I’m trying to do some basic geometry using trigonometry. For example to calculate angle A knowing that tan A = Opposite length/adjacent length.
I know how to use this ‘on paper’ but I just don’t know how to do it with the javascript functions! I’ve searched for an online tutorial but without much success.

This is for an experimental project to create simple program to build 3-d Graphics, just for the record.

Help appreciated.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@vinays84Jul 01.2008 — Your post is very sparse in detail and it's unclear exactly what you're asking for help in. Do you want someone to teach you trigonometry or do you have a specific geometric problem you wish to solve?

Regarding degrees vs radians, that can easily be solved with a transition function:
[CODE]
function toRad(deg) {
return deg * Math.PI/180;
}
[/CODE]


Then use Math.tan(toRad(variable_in_degrees)); Keep in mind that browsers round off values including PI, so if you called tan() or sin() of 180 deg you'd receive -1.2246063538223773e-16 instead of 0.
×

Success!

Help @ricardo76 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 5.20,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...