Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

The sinus function on a calculator, how to do in VB?

Hey guys,

I am bussy with a project for school and I want to make it a little bit easier by making a program that automatically calculates angles, but I need to know how I use SINUS (Sin button on calculator) in VB.

Someone maybe has an example code for me?

Thanks in advance!
Hi,

Here is the function, thanks Google :

PHP Code

<?php 
Public Shared Function Sin ( _
    a 
As Double _
) As Double 

a is in rad. So if you have deg first, you must do x*pi/180 🤫 to convert x into rad.

Here is a wonderful link, thanks Google : http://en.wikipedia.org/wiki/Sine

Example took from MSDN, thanks Google :

Code
' Example for the trigonometric Math.Sin( Double ) and Math.Cos( Double ) methods.
Imports System
Imports Microsoft.VisualBasic

Module SinCos

    Sub Main()
      Console.WriteLine( _
      "This example of trigonometric " & _
      "Math.Sin( double ) and Math.Cos( double )" & vbCrLf & _
      "generates the following output." & vbCrLf)
      Console.WriteLine( _
      "Convert selected values for X to radians " & vbCrLf & _
      "and evaluate these trigonometric identities:")
      Console.WriteLine( _
      "   sin^2(X) + cos^2(X) = 1" & vbCrLf & _
      "   sin(2 * X) = 2 * sin(X) * cos(X)")
      Console.WriteLine("   cos(2 * X) = cos^2(X) - sin^2(X)")

      UseSineCosine(15.0)
      UseSineCosine(30.0)
      UseSineCosine(45.0)

      Console.WriteLine( _
      vbCrLf & "Convert selected values for X and Y to radians" & _
      vbCrLf & "and evaluate these trigonometric identities:")
      Console.WriteLine("   sin(X + Y) = sin(X) * cos(Y) + cos(X) * sin(Y)")
      Console.WriteLine("   cos(X + Y) = cos(X) * cos(Y) - sin(X) * sin(Y)")

      UseTwoAngles(15.0, 30.0)
      UseTwoAngles(30.0, 45.0)
    End Sub 'Main

    ' Evaluate trigonometric identities with a given angle.
    Sub UseSineCosine(degrees As Double)

      Dim angle As Double = Math.PI * degrees / 180.0
      Dim sinAngle As Double = Math.Sin(angle)
      Dim cosAngle As Double = Math.Cos(angle)

      ' Evaluate sin^2(X) + cos^2(X) = 1.
      Console.WriteLine( _
      vbCrLf & "      Math.Sin({0} deg) = {1:E16}" & _
      vbCrLf & "      Math.Cos({0} deg) = {2:E16}", _
      degrees, Math.Sin(angle), Math.Cos(angle))
      Console.WriteLine( _
      "(Math.Sin({0} deg))^2 + (Math.Cos({0} deg))^2 = {1:E16}", _
      degrees, sinAngle * sinAngle + cosAngle * cosAngle)

      ' Evaluate sin(2 * X) = 2 * sin(X) * cos(X).
      Console.WriteLine( _
      "      Math.Sin({0} deg) = {1:E16}", _
      2.0 * degrees, Math.Sin(2.0 * angle))
      Console.WriteLine( _
      "    2 * Math.Sin({0} deg) * Math.Cos({0} deg) = {1:E16}", _
      degrees, 2.0 * sinAngle * cosAngle)

      ' Evaluate cos(2 * X) = cos^2(X) - sin^2(X).
      Console.WriteLine( _
      "      Math.Cos({0} deg) = {1:E16}", _
      2.0 * degrees, Math.Cos(2.0 * angle))
      Console.WriteLine( _
      "(Math.Cos({0} deg))^2 - (Math.Sin({0} deg))^2 = {1:E16}", _
      degrees, cosAngle * cosAngle - sinAngle * sinAngle)

    End Sub 'UseSineCosine

    ' Evaluate trigonometric identities that are functions of two angles.
    Sub UseTwoAngles(degreesX As Double, degreesY As Double)

      Dim angleX As Double = Math.PI * degreesX / 180.0
      Dim angleY As Double = Math.PI * degreesY / 180.0

      ' Evaluate sin(X + Y) = sin(X) * cos(Y) + cos(X) * sin(Y).
      Console.WriteLine( _
      vbCrLf & "      Math.Sin({0} deg) * Math.Cos({1} deg) +" & _
      vbCrLf & "      Math.Cos({0} deg) * Math.Sin({1} deg) = {2:E16}", _
      degreesX, degreesY, Math.Sin(angleX) * Math.Cos(angleY) + _
      Math.Cos(angleX) * Math.Sin(angleY))
      Console.WriteLine( _
      "      Math.Sin({0} deg) = {1:E16}", _
      degreesX + degreesY, Math.Sin(angleX + angleY))

      ' Evaluate cos(X + Y) = cos(X) * cos(Y) - sin(X) * sin(Y).
      Console.WriteLine( _
      "      Math.Cos({0} deg) * Math.Cos({1} deg) -" & vbCrLf & _
      "      Math.Sin({0} deg) * Math.Sin({1} deg) = {2:E16}", _
      degreesX, degreesY, Math.Cos(angleX) * Math.Cos(angleY) - _
      Math.Sin(angleX) * Math.Sin(angleY))
      Console.WriteLine( _
      "      Math.Cos({0} deg) = {1:E16}", _
      degreesX + degreesY, Math.Cos(angleX + angleY))

    End Sub 'UseTwoAngles
End Module 'SinCos

' This example of trigonometric Math.Sin( double ) and Math.Cos( double )
' generates the following output.
'
' Convert selected values for X to radians
' and evaluate these trigonometric identities:
'    sin^2(X) + cos^2(X) = 1
'    sin(2 * X) = 2 * sin(X) * cos(X)
'    cos(2 * X) = cos^2(X) - sin^2(X)
'
'      Math.Sin(15 deg) = 2.5881904510252074E-001
'      Math.Cos(15 deg) = 9.6592582628906831E-001
' (Math.Sin(15 deg))^2 + (Math.Cos(15 deg))^2 = 1.000000E+000
'      Math.Sin(30 deg) = 4.9999994E-001
'     2 * Math.Sin(15 deg) * Math.Cos(15 deg) = 4.9999994E-001
'      Math.Cos(30 deg) = 8.6602540378443871E-001
' (Math.Cos(15 deg))^2 - (Math.Sin(15 deg))^2 = 8.6602540378443871E-001
'
'      Math.Sin(30 deg) = 4.9999994E-001
'      Math.Cos(30 deg) = 8.6602540378443871E-001
' (Math.Sin(30 deg))^2 + (Math.Cos(30 deg))^2 = 1.000000E+000
'      Math.Sin(60 deg) = 8.6602540378443860E-001
'     2 * Math.Sin(30 deg) * Math.Cos(30 deg) = 8.6602540378443860E-001
'      Math.Cos(60 deg) = 5.00000011E-001
' (Math.Cos(30 deg))^2 - (Math.Sin(30 deg))^2 = 5.00000022E-001
'
'      Math.Sin(45 deg) = 7.0710678118654746E-001
'      Math.Cos(45 deg) = 7.0710678118654757E-001
' (Math.Sin(45 deg))^2 + (Math.Cos(45 deg))^2 = 1.000000E+000
'      Math.Sin(90 deg) = 1.000000E+000
'     2 * Math.Sin(45 deg) * Math.Cos(45 deg) = 1.000000E+000
'      Math.Cos(90 deg) = 6.1230317691118863E-017
' (Math.Cos(45 deg))^2 - (Math.Sin(45 deg))^2 = 2.2204460492503131E-016
'
' Convert selected values for X and Y to radians
' and evaluate these trigonometric identities:
'    sin(X + Y) = sin(X) * cos(Y) + cos(X) * sin(Y)
'    cos(X + Y) = cos(X) * cos(Y) - sin(X) * sin(Y)
'
'      Math.Sin(15 deg) * Math.Cos(30 deg) +
'      Math.Cos(15 deg) * Math.Sin(30 deg) = 7.0710678118654746E-001
'      Math.Sin(45 deg) = 7.0710678118654746E-001
'      Math.Cos(15 deg) * Math.Cos(30 deg) -
'      Math.Sin(15 deg) * Math.Sin(30 deg) = 7.0710678118654757E-001
'      Math.Cos(45 deg) = 7.0710678118654757E-001
'
'      Math.Sin(30 deg) * Math.Cos(45 deg) +
'      Math.Cos(30 deg) * Math.Sin(45 deg) = 9.6592582628906831E-001
'      Math.Sin(75 deg) = 9.6592582628906820E-001
'      Math.Cos(30 deg) * Math.Cos(45 deg) -
'      Math.Sin(30 deg) * Math.Sin(45 deg) = 2.5881904510252085E-001
'      Math.Cos(75 deg) = 2.5881904510252096E-001
Just call the static Sin method in the Math class.

Math.Sin(15.0)
(Oct 26, 2014 07:33 AM)Dialog Wrote:  Just call the static Sin method in the Math class.

Math.Sin(15.0)

15.0, does that just mean the angle is 15 degree?
(Oct 26, 2014 07:34 AM)AngularJS Wrote:  15.0, does that just mean the angle is 15 degree?

Just read my post carefully ... https://hackforums.net/showthread.php?ti...id43027175
(Oct 26, 2014 07:34 AM)AngularJS Wrote:  15.0, does that just mean the angle is 15 degree?

Yes. Taken from MSDN:
[Image: l2Z1fy5.png]

http://msdn.microsoft.com/en-us/library/...10%29.aspx
(Oct 26, 2014 07:40 AM)Dialog Wrote:  Yes. Taken from MSDN:
[Image: l2Z1fy5.png]

http://msdn.microsoft.com/en-us/library/...10%29.aspx
The thing is, when I put sin(15.0) in there, the outcome is 0,650

If I put it in my casio calculator it gives 0,259
(Oct 26, 2014 07:42 AM)AngularJS Wrote:  The thing is, when I put sin(15.0) in there, the outcome is 0,650

If I put it in my casio calculator it gives 0,259

That's because degree is not the same thing as radians ... Dialog seems to be tired ...
(Oct 26, 2014 07:44 AM)sqsgkrlhdwg Wrote:  That's because degree is not the same thing as radians ... Dialog seems to be tired ...

Oh, and is it impossible to get it to degrees?
(Oct 26, 2014 07:45 AM)AngularJS Wrote:  Oh, and is it impossible to get it to degrees?

You can do it. Just read this post. https://hackforums.net/showthread.php?ti...id43027258
You can convert rad to deg like this

deg = PI * rad / 180.0
(Oct 26, 2014 07:45 AM)AngularJS Wrote:  Oh, and is it impossible to get it to degrees?

L-EARN is correct. You'd have to multiply degrees by Math.PI divided by 180.
So it will be like this?

Code
Dim rad As Integer
      Dim deg As Integer
      rad = Math.Sin(15.0)
      deg = Math.PI * rad / 180.0
(Oct 26, 2014 07:57 AM)AngularJS Wrote:  So it will be like this?

Code
Dim rad As Integer
      Dim deg As Integer
      rad = Math.Sin(15.0)
      deg = Math.PI * rad / 180.0

I think you need to listen more in Maths class, this is simple math and you are getting it all wrong.
(Oct 26, 2014 07:57 AM)AngularJS Wrote:  So it will be like this?

Code
Dim rad As Integer
      Dim deg As Integer
      rad = Math.Sin(15.0)
      deg = Math.PI * rad / 180.0

No.

Code
Dim rad As Double
      Dim deg As Double
Dim sin As Double
      deg = 15.0
      rad = Math.PI * deg / 180.0
      sin = Math.Sin(rad)


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by FhackMar 2, 2022 03:52 AM 4 306 Mar 2, 2022 03:52 AM
Last Post: Fhack
[.NET] by CynnNov 6, 2014 06:17 AM 7 199 Nov 6, 2014 06:17 AM
Last Post: Cynn
[Python] by success = trueSep 14, 2013 07:05 PM 3 123 Sep 14, 2013 07:05 PM
Last Post: Dmaster_773