Jump to content

Math.Cos problem

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
chemart

chemart

    Newbie

  • Members
  • Pip
  • 6 posts
How do i make Math.Cos to use degrees instead of radians?

if angle is 90° :

cos(90)=0 << with degrees... this one is correct

90°/57.2957795 = 1.5708 radians

Math.Cos(90) = -0.44807361612917 wrong
Math.Cos(1.5708) = -3.58659263231679E-10 wrong

#2
Freedom Doc

Freedom Doc

    Newbie

  • Members
  • Pip
  • 8 posts

chemart said:

How do i make Math.Cos to use degrees instead of radians?

if angle is 90° :

cos(90)=0 << with degrees... this one is correct

90°/57.2957795 = 1.5708 radians

Math.Cos(90) = -0.44807361612917 wrong
Math.Cos(1.5708) = -3.58659263231679E-10 wrong

All computer languages that do trig do so with radian measure for the angles. You just need a simple formula to convert degrees to radians first. If you have x in degrees, then pi * x / 180 will be the right value for Math.Cos() (I forget if C# has a known constant for pi but 3.14159265358979 will do just fine).

By the way, the reason Math.Cos(1.5708) is not exactly zero is due to floating point roundoff problems + the fact that 1.5708 is not exactly pi / 2. Do not expect exact answers from a system that tries to represent infinitely many real numbers with only a finite number of items -- not gonna happen.

#3
yulin11

yulin11

    Newbie

  • Members
  • Pip
  • 7 posts
Yes ,i think you should convert the number you need.then use it in the math.cos.

codeuu

#4
jireh

jireh

    Newbie

  • Members
  • PipPip
  • 18 posts
just have the right logic and do the tricks...