Home All Groups Group Topic Archive Search About
Author
28 Feb 2007 5:25 PM
Akdogan
Hello All,
I have trouble with sinus and cosinus of angles.
In a form I defined some text boxes, and I am inputing the angles there. But
the code returns wrong values for their sýnuses or cýsinuses.

for instance I am writing
a1= sin(k1) (where k1 is in the text box and it is 45)
But the code does not return the correct result. Why?
Do I have to add more references.
Please any suggesstion...
Regards...
Akdogan

Author
28 Feb 2007 5:33 PM
Bob Butler
"Akdogan" <kamil.akdo***@ttnet.net.tr> wrote in message
news:eh2Ir11WHHA.4632@TK2MSFTNGP04.phx.gbl
> Hello All,
> I have trouble with sinus and cosinus of angles.
> In a form I defined some text boxes, and I am inputing the angles
> there. But the code returns wrong values for their sýnuses or
> cýsinuses.
>
> for instance I am writing
> a1= sin(k1) (where k1 is in the text box and it is 45)
> But the code does not return the correct result. Why?

Looks like you want the sine of 45 degrees but VB's functions use radians so
you have to convert the argument first

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
28 Feb 2007 5:49 PM
Akdogan
Thank you all,
You are right. The problem was with the conversion from rad to degree.
Regards...

"Bob Butler" <tiredofit@nospam.ever>, haber iletisinde sunlari
yazdi:e72ag61WHHA.***@TK2MSFTNGP06.phx.gbl...
Show quoteHide quote
> "Akdogan" <kamil.akdo***@ttnet.net.tr> wrote in message
> news:eh2Ir11WHHA.4632@TK2MSFTNGP04.phx.gbl
>> Hello All,
>> I have trouble with sinus and cosinus of angles.
>> In a form I defined some text boxes, and I am inputing the angles
>> there. But the code returns wrong values for their sýnuses or
>> cýsinuses.
>>
>> for instance I am writing
>> a1= sin(k1) (where k1 is in the text box and it is 45)
>> But the code does not return the correct result. Why?
>
> Looks like you want the sine of 45 degrees but VB's functions use radians
> so
> you have to convert the argument first
>
> --
> Reply to the group so all can participate
> VB.Net: "Fool me once..."
>
Author
28 Feb 2007 5:38 PM
Robert Morley
Sin and Cos (and all the other trig functions) work in radians in VB, not
degrees.  In order to convert, you have to multiply by Pi / 180.

    a1 = sin(k1 * 3.141592653589793 / 180)

Or, probably better, define Pi as a Constant or use the Atn(1) * 4 formula
to get it.  If you define it as a constant, and are worried about getting
absolute maximum precision, use:

    Public Const Pi = 3.14159265358979 + 0.000000000000003

NOT

    Public Const Pi = 3.141592653589793

Belive it or not, it DOES make a difference (at least assuming you EVER
compile your application after you've closed it and re-loaded the project).

If you want to use the formula instead, then it would be:

Public Function Pi() As Double
    Pi = Atn(1) * 4
End Function


Rob

Show quoteHide quote
"Akdogan" <kamil.akdo***@ttnet.net.tr> wrote in message
news:eh2Ir11WHHA.4632@TK2MSFTNGP04.phx.gbl...
> Hello All,
> I have trouble with sinus and cosinus of angles.
> In a form I defined some text boxes, and I am inputing the angles there.
> But the code returns wrong values for their sýnuses or cýsinuses.
>
> for instance I am writing
> a1= sin(k1) (where k1 is in the text box and it is 45)
> But the code does not return the correct result. Why?
> Do I have to add more references.
> Please any suggesstion...
> Regards...
> Akdogan
>
>
Author
28 Feb 2007 5:43 PM
Rick Rothstein (MVP - VB)
> I have trouble with sinus and cosinus of angles.
> In a form I defined some text boxes, and I am inputing the angles there.
> But the code returns wrong values for their sýnuses or cýsinuses.
>
> for instance I am writing
> a1= sin(k1) (where k1 is in the text box and it is 45)
> But the code does not return the correct result. Why?
> Do I have to add more references.
> Please any suggesstion...

VB's trig functions use Radians for the angles (45 looks like it is probably
in Degrees). You can convert Degrees to Radians like this...

PI = 3.14159265358979
Radians = Degrees * PI / 180

and you can go the other way like this...

PI = 3.14159265358979
Degrees = Radians * 180 / PI

You can declare PI as a Const(ant) and declare the Radians and Degrees
variables as Singles or Doubles depending on what you need.

Rick