Skip to content

Instantly share code, notes, and snippets.

@knzm
Created May 26, 2012 20:53
Show Gist options
  • Select an option

  • Save knzm/2795266 to your computer and use it in GitHub Desktop.

Select an option

Save knzm/2795266 to your computer and use it in GitHub Desktop.
>>> 1 + 2j
(1+2j)
>>> type(1 + 2j)
<type 'complex'>
>>> from math import sin, cos, pi
>>> def rotate(th): return cos(th)+sin(th)*1j
...
>>> rotate(pi/6)
(0.8660254037844387+0.49999999999999994j)
>>> rotate30 = 0.866+0.5j
>>> rotate(pi/4)
(0.7071067811865476+0.7071067811865475j)
>>> rotate45 = 0.707+0.707j
>>> rotate(pi/3)
(0.5000000000000001+0.8660254037844386j)
>>> rotate60 = 0.5+0.866j
>>> v = 1
>>> v *= rotate30
>>> v *= rotate30
>>> v *= rotate30
>>> x, y = v.real, v.imag
>>> x, y
(-3.8104000000038774e-05, 0.9999339999999999)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment