From f0ba6f40689544cc902909fcb1f55bddf117c69b Mon Sep 17 00:00:00 2001 From: Wirawan Purwanto Date: Mon, 9 Dec 2013 17:27:44 -0500 Subject: [PATCH] * wpylib.math: Added complex_polar(). --- math/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/math/__init__.py b/math/__init__.py index 8862234..b2569b4 100644 --- a/math/__init__.py +++ b/math/__init__.py @@ -85,3 +85,11 @@ def choose(n,r): for (num,denom) in zip(xrange(n,n-r,-1), xrange(1,r+1,1)): c = (c * num) // denom return c + + +def complex_polar(r, theta): + """Generates regular complex data (scalar or array) from + an input magnitude and angle.""" + from numpy import sin, cos + # This way will be friendly for arrays: + return r * cos(theta) + 1j * r * sin(theta)