title: Python Trig Functions Return Complex Numbers?
body: <p>
  I am writing code that accepts the degree by which a motor turns and uses that data to calculate the distance covered by the wheels (using distance = no. of rotations * distance covered per rotation). </p>
  
  <p>It then makes an error adjustment (taking into consideration environmental factors such as friction).</p>
  
  <p>Finally, using trigonometry, it calculates the distance moved along the x-axis and y-axis.</p>
  
  <p>All the above is done by the function <code>straight</code> contained within the class <code>CoordinateManager</code>. This function is called by an instance of another class.</p>
  
  <pre><code>class CoordinateManager:
      goalcord = [20, 0]
  
      def __init__(self):
          self.curcord = [0, 0]
          self.theta = 0
  
      def get_compass_angle(self):
          compass = Sensor(address='in2')
          return compass.value(0)
  
      def turn(self, iangle, fangle):
          self.theta = self.theta + (fangle-iangle)
  
      def straight(self, turnangle):
          d = turnangle*2*3.14*2/360
          d = 1.8120132*(d**0.8938054)
          thetarad = radians(self.theta)
          dx = d*sin(thetarad)
          dy = d*cos(thetarad)
          self.curcord[0] += dx
          self.curcord[1] += dy
  </code></pre>
  
  <p>Printing both <code>d</code> and <code>self.theta</code> shows that they contain correct values. </p>
  
  <p>This must mean that the array <code>self.curcord</code> has valid values too. However, this has not been the case. Printing the two elements of <code>self.curcord</code> outputs complex numbers (some big float + another big float<strong>j</strong>). </p>
  
  <p>I can think of no logical explanation for this other than that the trigonometric functions must be returning complex numbers. However, I think the chances that a python built-in lib function returns wrong values are extraordinarily slim.</p>
  
  <p>Is there any logical error that I may be overlooking?</p>
  
  <p>Edit: I just tried changing the last two lines to:</p>
  
  <pre><code>self.curcord[0] += dx
  self.curcord[1] += dy
  </code></pre>
  
  <p>I just tried using <code>.real</code> when displaying the values. Even though the values are real now, they are still wrong. I will look further into whether this is caused by some calculation error.</p>