Trigonometric Methods
The Math object supports the trigonometric methods in Table 6-2. The arguments for the Sin(), Cos(), and Tan() methods need to be given in radians. The return values of ArcSin(), ArcCos(), and ArcTan() are also in radians. If you remember, 180 degrees is equal to Pi radians. So you’ll have to convert degrees to radians (this is math’s fault, not Small Basic’s). To make this easier, the Math object includes the GetDegrees() and GetRadians() methods. (In other words, typing Math.Sin() won’t tell you how much you sinned today, and typing Math.Tan() won’t give you a running percentage on your tan.)
Table: Trigonometric methods available in the Math object
Method |
Description |
GetDegrees(rad) |
Converts a given radian angle to degrees |
GetRadians(deg) |
Converts a given angle in degrees to radians |
Sin(rad) |
Returns the sine of the given radian angle |
Cos(rad) |
Returns the cosine of the given radian angle |
Tan(rad) |
Returns the tangent of the given radian angle |
ArcSin(value) |
Returns the angle (in radians) for the given sine value |
ArcCos(value) |
Returns the angle (in radians) for the cosine value |
ArcTan(value) |
Returns the angle (in radians) for the tangent value |
This next code snippet shows you what using these methods looks like:
Math.GetDegrees( Math.Pi ) ' = 180
Math.GetRadians( 90 ) ' = 1.5707963267949
Math.Sin( Math.GetRadians(30) ) ' = 0.5
Math.Cos( Math.GetRadians(60) ) ' = 0.499999999999998
Math.Tan( Math.GetRadians(45) ) ' = 0.999999999999999
Math.GetDegrees( Math.ArcSin(0.5) ) ' = 30
Math.GetDegrees( Math.ArcCos(0.5) ) ' = 60.0000000000001
Math.GetDegrees( Math.ArcTan(1.0) ) ' = 45
Now let's learn about Radians!
Radians
A circle can be divided into 360 degrees. 1 degree is 1/360th of a circle, 90 degrees is 1/4th of a circle, 180 degrees is 1/2 a circle, and so on. Radian measurement, on the other hand, is based on the circumference (C) of a circle, which is given by:
C = 2 p ´ (radius)
If radius is 1 (a unit circle), the circumference is: C = 2p.
And that’s why a circle has 360 degrees, or 2p radians. 90 degrees would then be 2p/4 (or p/2) radians, and 180 degrees is equivalent to p radians. Using radians has some benefits, but it takes some time to get used to it.
Go to http://blogs.msdn.com/SmallBasic to download Small Basic for free and learn all about it!
Reply with any questions or comments! And...
Have a Small and Basic day!
- Majed Marji & Ed Price
Computers Today (part 1 of 6)
blogs.msdn.com/.../computers-today.aspx
.....
CS SPOTLIGHT: Girls in computer programming... why it matters!!!
blogs.msdn.com/.../cs-spotlight-girls-in-computer-programming-why-it-matters.aspx
...
Computational Thinking - Videos & Papers by Jeannette Wing
blogs.msdn.com/.../computational-thinking-videos-amp-papers-by-jeannette-wing.aspx
Trigonometric ratios, fast app to find: sine, cosine, tangent, cotangent, secant and consecante of an angle
https://en.wikipedia.org/wiki/Trigonometric_functions#sec