help with cosine and sine computations!

resha
06-23-2005, 11:19 AM
hello.

i have a problem with VB's cos and sin compuation. it uses radians and i need a degree computation. VB treats the number i enter as radians and i want it to be treated as a degree.

if i enter the value 90, VB will compute the cosine and sine of 90 in radian mode. i need the cosine and sine of 90 in degree mode. as you well know, there is a big difference between the cosines and sines of radian and degree.

i enter the value 90.
what i get is 90 treated as radian.
cos 90 (radian) = -0.4481
sin 90 (radian) = 0.8940

what i need is 90 be treated as degrees or to be able to display the degree computations for it.
cos 90 (degree) = 0
sin 90 (degree) = 1

if i enter 60, the trigonometric functions SHOULD give the answer of:
cos 60 = 0.5
sin 60 = 0.866
and so on and so forth depending on what value i enter.

could someone please help me? :confused:

thanks.

TeraBlight
06-23-2005, 11:41 AM
Dim radsPerDeg As Double: radsPerDeg = Atn(1) / 45
Dim degsPerRad As Double: degsPerRad = 1 / radsPerDeg

MsgBox 180 * radsPerDeg 'gives Pi
MsgBox 3.141593 * degsPerRad 'gives 180

MsgBox Sin(30 * radsPerDeg) 'gives 0.5

It's tedious, but you have to do it "manually".
If you have a lot of these calculations, you might want to write a function called sinDegs that takes an angle in degrees and converts it before applying the sin-function.

resha
06-23-2005, 11:53 AM
Dim radsPerDeg As Double: radsPerDeg = Atn(1) / 45
Dim degsPerRad As Double: degsPerRad = 1 / radsPerDeg

MsgBox 180 * radsPerDeg 'gives Pi
MsgBox 3.141593 * degsPerRad 'gives 180

MsgBox Sin(30 * radsPerDeg) 'gives 0.5

It's tedious, but you have to do it "manually".
If you have a lot of these calculations, you might want to write a function called sinDegs that takes an angle in degrees and converts it before applying the sin-function.


could you please tell me what 'Atn' is? and the degree is not fixed value but is a user-input. would the above syntax still be applicable?

thank you very much.

TeraBlight
06-23-2005, 11:59 AM
Atn is arctangent. The arctangent of 1 is pi/4 (when the adjacent and the opposite are equal, the angle is 45 degrees). All it's doing is avoiding having to look up and type in PI manually. You can replace

Atn(1)/45

by

3.141593/180

if you prefer.
And yes, it will work no matter where the number of degrees comes from, sure thing :)

resha
06-23-2005, 12:05 PM
thank you very much! you saved my program for my project! ^_^

this will make me cut my computation time in half.

thank you, thank you very much. ^_^

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum