Python cmath 模块,polar() 实例源码

我们从Python开源项目中,提取了以下21个代码示例,用于说明如何使用cmath.polar()

项目:QuickJoint    作者:JarrettR    | 项目源码 | 文件源码
def get_length(self, line):
        polR, polPhi = cmath.polar(line)
        return polR
项目:QuickJoint    作者:JarrettR    | 项目源码 | 文件源码
def draw_parallel(self, start, guideLine, stepDistance):
        polR, polPhi = cmath.polar(guideLine)
        polR = stepDistance
        return (cmath.rect(polR, polPhi) + start)
项目:QuickJoint    作者:JarrettR    | 项目源码 | 文件源码
def draw_perpendicular(self, start, guideLine, stepDistance, invert = False):
        polR, polPhi = cmath.polar(guideLine)
        polR = stepDistance
        debugMsg(polPhi)
        if invert:  
            polPhi += (cmath.pi / 2)
        else:
            polPhi -= (cmath.pi / 2)
        debugMsg(polPhi)
        debugMsg(cmath.rect(polR, polPhi))
        return (cmath.rect(polR, polPhi) + start)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_polar(self):
        self.assertCISEqual(polar(0), (0., 0.))
        self.assertCISEqual(polar(1.), (1., 0.))
        self.assertCISEqual(polar(-1.), (1., pi))
        self.assertCISEqual(polar(1j), (1., pi/2))
        self.assertCISEqual(polar(-1j), (1., -pi/2))
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_polar(self):
        self.check_polar(polar)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_polar_errno(self):
        # Issue #24489: check a previously set C errno doesn't disturb polar()
        from _testcapi import set_errno
        def polar_with_errno_set(z):
            set_errno(11)
            try:
                return polar(z)
            finally:
                set_errno(0)
        self.check_polar(polar_with_errno_set)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_polar(self):
        self.check_polar(polar)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_polar_errno(self):
        # Issue #24489: check a previously set C errno doesn't disturb polar()
        from _testcapi import set_errno
        def polar_with_errno_set(z):
            set_errno(11)
            try:
                return polar(z)
            finally:
                set_errno(0)
        self.check_polar(polar_with_errno_set)
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_polar(self):
        self.assertCISEqual(polar(0), (0., 0.))
        self.assertCISEqual(polar(1.), (1., 0.))
        self.assertCISEqual(polar(-1.), (1., pi))
        self.assertCISEqual(polar(1j), (1., pi/2))
        self.assertCISEqual(polar(-1j), (1., -pi/2))
项目:PhasorToolBox    作者:sonusz    | 项目源码 | 文件源码
def __init__(self, _io, _parent=None, _root=None, _conversion_factor=None):
                    self._conversion_factor = _conversion_factor
                    self._io = _io
                    self._parent = _parent
                    self._root = _root if _root else self
                    _on = self._parent._parent._station.format.rectangular_or_polar
                    if _on == 'rectangular':
                        self.phasors = self._root.PmuData.Phasors.Int.Rectangular(
                            self._io, self, self._root, self._conversion_factor)
                    elif _on == 'polar':
                        self.phasors = self._root.PmuData.Phasors.Int.Polar(
                            self._io, self, self._root, self._conversion_factor)
项目:PhasorToolBox    作者:sonusz    | 项目源码 | 文件源码
def magnitude(self):
                        if hasattr(self, '_m_magnitude'):
                            return self._m_magnitude if hasattr(self, '_m_magnitude') else None

                        self._m_magnitude, self._m_angle = cmath.polar(
                            complex(self.real, self.imaginary))
                        return self._m_magnitude if hasattr(self, '_m_magnitude') else None
项目:PhasorToolBox    作者:sonusz    | 项目源码 | 文件源码
def angle(self):
                        if hasattr(self, '_m_angle'):
                            return self._m_angle if hasattr(self, '_m_angle') else None

                        self._m_magnitude, self._m_angle = cmath.polar(
                            complex(self.real, self.imaginary))
                        return self._m_angle if hasattr(self, '_m_angle') else None
项目:PhasorToolBox    作者:sonusz    | 项目源码 | 文件源码
def __init__(self, _io, _parent=None, _root=None):
                    self._io = _io
                    self._parent = _parent
                    self._root = _root if _root else self
                    _on = self._parent._parent._station.format.rectangular_or_polar
                    if _on == 'rectangular':
                        self.phasors = self._root.PmuData.Phasors.Float.Rectangular(
                            self._io, self, self._root)
                    elif _on == 'polar':
                        self.phasors = self._root.PmuData.Phasors.Float.Polar(
                            self._io, self, self._root)
项目:PhasorToolBox    作者:sonusz    | 项目源码 | 文件源码
def magnitude(self):
                        if hasattr(self, '_m_magnitude'):
                            return self._m_magnitude if hasattr(self, '_m_magnitude') else None

                        self._m_magnitude, self._m_angle = cmath.polar(
                            complex(self.real, self.imaginary))
                        return self._m_magnitude if hasattr(self, '_m_magnitude') else None
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def test_polar(self):
        self.assertCISEqual(polar(0), (0., 0.))
        self.assertCISEqual(polar(1.), (1., 0.))
        self.assertCISEqual(polar(-1.), (1., pi))
        self.assertCISEqual(polar(1j), (1., pi/2))
        self.assertCISEqual(polar(-1j), (1., -pi/2))
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_polar(self):
        self.check_polar(polar)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_polar_errno(self):
        # Issue #24489: check a previously set C errno doesn't disturb polar()
        from _testcapi import set_errno
        def polar_with_errno_set(z):
            set_errno(11)
            try:
                return polar(z)
            finally:
                set_errno(0)
        self.check_polar(polar_with_errno_set)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def test_polar(self):
        self.assertCISEqual(polar(0), (0., 0.))
        self.assertCISEqual(polar(1.), (1., 0.))
        self.assertCISEqual(polar(-1.), (1., pi))
        self.assertCISEqual(polar(1j), (1., pi/2))
        self.assertCISEqual(polar(-1j), (1., -pi/2))
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_polar(self):
        self.assertCISEqual(polar(0), (0., 0.))
        self.assertCISEqual(polar(1.), (1., 0.))
        self.assertCISEqual(polar(-1.), (1., pi))
        self.assertCISEqual(polar(1j), (1., pi/2))
        self.assertCISEqual(polar(-1j), (1., -pi/2))
项目:QuickJoint    作者:JarrettR    | 项目源码 | 文件源码
def draw_box(self, start, guideLine, xDistance, yDistance, kerf):
        polR, polPhi = cmath.polar(guideLine)

        #Kerf expansion
        if self.flipside:  
            start -= cmath.rect(kerf / 2, polPhi)
            start -= cmath.rect(kerf / 2, polPhi + (cmath.pi / 2))
        else:
            start -= cmath.rect(kerf / 2, polPhi)
            start -= cmath.rect(kerf / 2, polPhi - (cmath.pi / 2))

        lines = []
        lines.append(['M', [start.real, start.imag]])

        #Horizontal
        polR = xDistance
        move = cmath.rect(polR + kerf, polPhi) + start
        lines.append(['L', [move.real, move.imag]])
        start = move

        #Vertical
        polR = yDistance
        if self.flipside:  
            polPhi += (cmath.pi / 2)
        else:
            polPhi -= (cmath.pi / 2)
        move = cmath.rect(polR  + kerf, polPhi) + start
        lines.append(['L', [move.real, move.imag]])
        start = move

        #Horizontal
        polR = xDistance
        if self.flipside:  
            polPhi += (cmath.pi / 2)
        else:
            polPhi -= (cmath.pi / 2)
        move = cmath.rect(polR + kerf, polPhi) + start
        lines.append(['L', [move.real, move.imag]])
        start = move

        lines.append(['Z', []])

        return lines
项目:QuickJoint    作者:JarrettR    | 项目源码 | 文件源码
def draw_slots(self, path):
        #Female slot creation

        start = self.to_complex(path[0][1])
        end = self.to_complex(path[1][1])

        if self.edgefeatures == False:
            segCount = (self.numslots * 2) 
        else:
            segCount = (self.numslots * 2) - 1

        distance = end - start
        debugMsg(distance)
        debugMsg("segCount - " + str(segCount))

        try:
            if self.edgefeatures:
                segLength = self.get_length(distance) / segCount
            else:
                segLength = self.get_length(distance) / (segCount + 1)
        except:
            segLength = self.get_length(distance)

        debugMsg("segLength - " + str(segLength))
        newLines = []

        line_style = simplestyle.formatStyle({ 'stroke': '#000000', 'fill': 'none', 'stroke-width': str(self.unittouu('1px')) })

        for i in range(segCount):
            if (self.edgefeatures and (i % 2) == 0) or (not self.edgefeatures and (i % 2)):
                newLines = self.draw_box(start, distance, segLength, self.thickness, self.kerf)
                debugMsg(newLines)

                slot_id = self.uniqueId('slot')
                g = inkex.etree.SubElement(self.current_layer, 'g', {'id':slot_id})

                line_atts = { 'style':line_style, 'id':slot_id+'-inner-close-tab', 'd':simplepath.formatPath(newLines) }
                inkex.etree.SubElement(g, inkex.addNS('path','svg'), line_atts )

            #Find next point
            polR, polPhi = cmath.polar(distance)
            polR = segLength
            start = cmath.rect(polR, polPhi) + start