|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
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 "Akdogan" <kamil.akdo***@ttnet.net.tr> wrote in message Looks like you want the sine of 45 degrees but VB's functions use radians sonews: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? you have to convert the argument first -- Reply to the group so all can participate VB.Net: "Fool me once..." 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..." > 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 > > > I have trouble with sinus and cosinus of angles. VB's trig functions use Radians for the angles (45 looks like it is probably > 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... 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
Within a *.exe
Function that returns an Array Reason for 'Set' keyword SendKeys command fails on Vista Error in reading large csv file Should I or shouldn't I include excel.exe in my app distribution package? Getting Info from a .TTF File Cannot quit Excel called from VB6 Source Control via Network Drive TaskBar won't show when hidden. |
|||||||||||||||||||||||