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

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

项目:micropython-tft-gui    作者:peterhinch    | 项目源码 | 文件源码
def show(self):
        tft = self.tft
        x0 = self.x0
        y0 = self.y0
        radius = self.radius
        diam = 2 * radius
        if self.rdivs > 0:
            for r in range(1, self.rdivs + 1):
                tft.draw_circle(self.xp_origin, self.yp_origin, int(radius * r / self.rdivs), self.gridcolor)
        if self.adivs > 0:
            v = complex(1)
            m = rect(1, pi / self.adivs)
            for _ in range(self.adivs):
                self.cline(-v, v, self.gridcolor)
                v *= m
        tft.draw_vline(x0 + radius, y0, diam, self.fgcolor)
        tft.draw_hline(x0, y0 + radius, diam, self.fgcolor)
        for curve in self.curves:
            curve.show()
项目:micropython-lcd160cr-gui    作者:peterhinch    | 项目源码 | 文件源码
def show(self):
        tft = self.tft
        x0 = self.x0
        y0 = self.y0
        radius = self.radius
        diam = 2 * radius
        if self.rdivs > 0:
            for r in range(1, self.rdivs + 1):
                tft.draw_circle(self.xp_origin, self.yp_origin, int(radius * r / self.rdivs), self.gridcolor)
        if self.adivs > 0:
            v = complex(1)
            m = rect(1, pi / self.adivs)
            for _ in range(self.adivs):
                self.cline(-v, v, self.gridcolor)
                v *= m
        tft.draw_vline(x0 + radius, y0, diam, self.fgcolor)
        tft.draw_hline(x0, y0 + radius, diam, self.fgcolor)
        for curve in self.curves:
            curve.show()
项目: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)
项目:CON-SAI    作者:SSL-Roots    | 项目源码 | 文件源码
def __init__(self, center , theta):

        normalizedTheta = normalize(theta)
        self._c_center = center.x + center.y * 1.0j
        self._c_rotate = cmath.rect(1.0,normalizedTheta) 
        self._c_angle = normalizedTheta
项目:micropython-tft-gui    作者:peterhinch    | 项目源码 | 文件源码
def populate(self, curve):
        def f(theta):
            return rect(sin(3 * theta), theta) # complex
        nmax = 150
        for n in range(nmax + 1):
            theta = 2 * pi * n / nmax
            curve.point(f(theta))

# Test clipping
项目:micropython-tft-gui    作者:peterhinch    | 项目源码 | 文件源码
def __init__(self):
        super().__init__()
        backbutton(390, 242)
        fwdbutton(390, 0, BackScreen)
        g = PolarGraph((10, 10), border = 4)
        clearbutton(390, 70, g)
        curve = PolarCurve(g, self.populate, (1,))
        curve1 = PolarCurve(g, self.populate, (rect(1, pi/5),), color=RED)
        refreshbutton(390, 140, (curve, curve1))
项目:micropython-tft-gui    作者:peterhinch    | 项目源码 | 文件源码
def populate(self, curve, rot):
        def f(theta):
            return rect(1.15*sin(5 * theta), theta)*rot # complex
        nmax = 150
        for n in range(nmax + 1):
            theta = 2 * pi * n / nmax
            curve.point(f(theta))

# Simple Cartesian plot with asymmetric axis and two curves.
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_rect(self):
        self.assertCEqual(rect(0, 0), (0, 0))
        self.assertCEqual(rect(1, 0), (1., 0))
        self.assertCEqual(rect(1, -pi), (-1., 0))
        self.assertCEqual(rect(1, pi/2), (0, 1.))
        self.assertCEqual(rect(1, -pi/2), (0, -1.))
项目:SCOUT    作者:johngroves    | 项目源码 | 文件源码
def mean_heading(headings):
    """
    Calculate the average heading from a list of headings
    :param headings:
    :return: average heading
    """
    vectors = [cmath.rect(1, radians(angle)) for angle in headings]
    vector_sum = sum(vectors)
    return degrees(cmath.phase(vector_sum))
项目:tk_tools    作者:slightlynybbled    | 项目源码 | 文件源码
def set_value(self, number: float):
        """
        Sets the value of the graphic

        :param number: the number (must be between 0 and 'max_range'
        or the scale will peg the limits
        :return: None
        """
        self.canvas.delete('all')
        self.canvas.create_image(0, 0, image=self.image, anchor='nw')

        number = number if number <= self.max_value else self.max_value
        number = 0.0 if number < 0.0 else number

        radius = 0.9 * self.size/2.0
        angle_in_radians = (2.0 * cmath.pi / 3.0) \
            + number / self.max_value * (5.0 * cmath.pi / 3.0)

        center = cmath.rect(0, 0)
        outer = cmath.rect(radius, angle_in_radians)
        if self.needle_thickness == 0:
            line_width = int(5 * self.size / 200)
            line_width = 1 if line_width < 1 else line_width
        else:
            line_width = self.needle_thickness

        self.canvas.create_line(
            *self.to_absolute(center.real, center.imag),
            *self.to_absolute(outer.real, outer.imag),
            width=line_width,
            fill=self.needle_color
        )

        self.readout['text'] = '{}{}'.format(number, self.unit)
项目:tk_tools    作者:slightlynybbled    | 项目源码 | 文件源码
def draw_background(self, divisions=10):
        """
        Draws the background of the dial

        :param divisions: the number of divisions
        between 'ticks' shown on the dial
        :return: None
        """
        self.canvas.create_arc(2, 2, self.size-2, self.size-2,
                               style=tk.PIESLICE, start=-60, extent=30,
                               fill='red')
        self.canvas.create_arc(2, 2, self.size-2, self.size-2,
                               style=tk.PIESLICE, start=-30, extent=60,
                               fill='yellow')
        self.canvas.create_arc(2, 2, self.size-2, self.size-2,
                               style=tk.PIESLICE, start=30, extent=210,
                               fill='green')

        # find the distance between the center and the inner tick radius
        inner_tick_radius = int(self.size * 0.4)
        outer_tick_radius = int(self.size * 0.5)

        for tick in range(divisions):
            angle_in_radians = (2.0 * cmath.pi / 3.0) \
                               + tick/divisions * (5.0 * cmath.pi / 3.0)
            inner_point = cmath.rect(inner_tick_radius, angle_in_radians)
            outer_point = cmath.rect(outer_tick_radius, angle_in_radians)

            self.canvas.create_line(
                *self.to_absolute(inner_point.real, inner_point.imag),
                *self.to_absolute(outer_point.real, outer_point.imag),
                width=1
            )
项目:tk_tools    作者:slightlynybbled    | 项目源码 | 文件源码
def draw_axes(self):
        """
        Removes all existing series and re-draws the axes

        :return: None
        """
        self.canvas.delete('all')
        rect = 50, 50, self.w - 50, self.h - 50

        self.canvas.create_rectangle(rect, outline="black")

        for x in self.frange(0, self.x_max - self.x_min + 1, self.x_tick):
            value = Decimal(self.x_min + x)
            if self.x_min <= value <= self.x_max:
                x_step = (self.px_x * x) / self.x_tick
                coord = 50 + x_step, self.h - 50, 50 + x_step, self.h - 45
                self.canvas.create_line(coord, fill="black")
                coord = 50 + x_step, self.h - 40

                label = round(Decimal(self.x_min + x), 1)
                self.canvas.create_text(coord, fill="black", text=label)

        for y in self.frange(0, self.y_max - self.y_min + 1, self.y_tick):
            value = Decimal(self.y_max - y)

            if self.y_min <= value <= self.y_max:
                y_step = (self.px_y * y) / self.y_tick
                coord = 45, 50 + y_step, 50, 50 + y_step
                self.canvas.create_line(coord, fill="black")
                coord = 35, 50 + y_step

                label = round(value, 1)
                self.canvas.create_text(coord, fill="black", text=label)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_rect(self):
        self.assertCEqual(rect(0, 0), (0, 0))
        self.assertCEqual(rect(1, 0), (1., 0))
        self.assertCEqual(rect(1, -pi), (-1., 0))
        self.assertCEqual(rect(1, pi/2), (0, 1.))
        self.assertCEqual(rect(1, -pi/2), (0, -1.))
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_rect(self):
        self.assertCEqual(rect(0, 0), (0, 0))
        self.assertCEqual(rect(1, 0), (1., 0))
        self.assertCEqual(rect(1, -pi), (-1., 0))
        self.assertCEqual(rect(1, pi/2), (0, 1.))
        self.assertCEqual(rect(1, -pi/2), (0, -1.))
项目:mh370_sat_tools    作者:kprostyakov    | 项目源码 | 文件源码
def make_residual_func(samples, indices, **params):
    'closure for residual func'
    fft_size = 2
    while fft_size < indices[-1]:
        fft_size *= 2
    freqs = rfftfreq(fft_size, 5)
    ind_from = int(round(1/(params['t_max']*freqs[1])))
    ind_to = ind_from+params['n_harm']
    def make_series(x):
        'Calculates time series from parameterized spectrum'
        nonlocal freqs, ind_from, ind_to, params
        spectrum = zeros_like(freqs, 'complex')
        sign_x0 = 0 if x[0] == 0.5 else abs(x[0]-0.5)/(x[0]-0.5)
        spectrum[0] = rect(sign_x0*exp(params['scale'][0]*abs(x[0]-0.5)), 0)
        for i in range(ind_from, ind_to):
            spectrum[i] = rect(
                exp(params['scale'][1]*x[1]+params['slope']*log(freqs[i])),
                params['scale'][2]*x[2+i-ind_from]
            )
        return irfft(spectrum)
    def residual_func(x):
        'calculates sum of squared residuals'
        nonlocal samples, indices
        series = make_series(x)
        sum_err = 0
        for position, ind in enumerate(indices):
            sum_err += (series[ind]-samples[position])**2
        return sum_err
    return make_series, residual_func
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_rect(self):
        self.assertCEqual(rect(0, 0), (0, 0))
        self.assertCEqual(rect(1, 0), (1., 0))
        self.assertCEqual(rect(1, -pi), (-1., 0))
        self.assertCEqual(rect(1, pi/2), (0, 1.))
        self.assertCEqual(rect(1, -pi/2), (0, -1.))
项目:PhasorToolBox    作者:sonusz    | 项目源码 | 文件源码
def real(self):
                        if hasattr(self, '_m_real'):
                            return self._m_real if hasattr(self, '_m_real') else None

                        z = cmath.rect(self.magnitude, self.angle)
                        self._m_real, self._m_imaginary = z.real, z.imag
                        return self._m_real if hasattr(self, '_m_real') else None
项目:PhasorToolBox    作者:sonusz    | 项目源码 | 文件源码
def imaginary(self):
                        if hasattr(self, '_m_imaginary'):
                            return self._m_imaginary if hasattr(self, '_m_imaginary') else None

                        z = cmath.rect(self.magnitude, self.angle)
                        self._m_real, self._m_imaginary = z.real, z.imag
                        return self._m_imaginary if hasattr(self, '_m_imaginary') else None
项目:PhasorToolBox    作者:sonusz    | 项目源码 | 文件源码
def real(self):
                        if hasattr(self, '_m_real'):
                            return self._m_real if hasattr(self, '_m_real') else None

                        z = cmath.rect(self.magnitude, self.angle)
                        self._m_real, self._m_imaginary = z.real, z.imag
                        return self._m_real if hasattr(self, '_m_real') else None
项目:PhasorToolBox    作者:sonusz    | 项目源码 | 文件源码
def imaginary(self):
                        if hasattr(self, '_m_imaginary'):
                            return self._m_imaginary if hasattr(self, '_m_imaginary') else None

                        z = cmath.rect(self.magnitude, self.angle)
                        self._m_real, self._m_imaginary = z.real, z.imag
                        return self._m_imaginary if hasattr(self, '_m_imaginary') else None
项目:picasso    作者:jungmannlab    | 项目源码 | 文件源码
def mean_angle(self, deg):
        return (phase(sum(rect(1, d) for d in deg)/len(deg)))
项目:kiwiclient    作者:dev-zzo    | 项目源码 | 文件源码
def __init__(self, fc):
        "fc is the LO frequency divided by the sample rate"
        self._w = cmath.rect(1, -fc * 2 * math.pi)
        self._v = complex(1)
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def test_rect(self):
        self.assertCEqual(rect(0, 0), (0, 0))
        self.assertCEqual(rect(1, 0), (1., 0))
        self.assertCEqual(rect(1, -pi), (-1., 0))
        self.assertCEqual(rect(1, pi/2), (0, 1.))
        self.assertCEqual(rect(1, -pi/2), (0, -1.))
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_rect(self):
        self.assertCEqual(rect(0, 0), (0, 0))
        self.assertCEqual(rect(1, 0), (1., 0))
        self.assertCEqual(rect(1, -pi), (-1., 0))
        self.assertCEqual(rect(1, pi/2), (0, 1.))
        self.assertCEqual(rect(1, -pi/2), (0, -1.))
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def test_rect(self):
        self.assertCEqual(rect(0, 0), (0, 0))
        self.assertCEqual(rect(1, 0), (1., 0))
        self.assertCEqual(rect(1, -pi), (-1., 0))
        self.assertCEqual(rect(1, pi/2), (0, 1.))
        self.assertCEqual(rect(1, -pi/2), (0, -1.))
项目:micropython-lcd160cr-gui    作者:peterhinch    | 项目源码 | 文件源码
def populate(self, curve):
        def f(theta):
            return rect(sin(3 * theta), theta) # complex
        nmax = 150
        for n in range(nmax + 1):
            theta = 2 * pi * n / nmax
            curve.point(f(theta))

# Test clipping
项目:micropython-lcd160cr-gui    作者:peterhinch    | 项目源码 | 文件源码
def __init__(self):
        super().__init__()
        backbutton()
        ovlbutton()
        g = PolarGraph((5, 5), border = 4, height=110)
        clearbutton(g)
        curve = PolarCurve(g, self.populate, (1,))
        curve1 = PolarCurve(g, self.populate, (rect(1, pi/5),), color=RED)
        refreshbutton((curve, curve1))
项目:micropython-lcd160cr-gui    作者:peterhinch    | 项目源码 | 文件源码
def populate(self, curve, rot):
        def f(theta):
            return rect(1.15*sin(5 * theta), theta)*rot # complex
        nmax = 150
        for n in range(nmax + 1):
            theta = 2 * pi * n / nmax
            curve.point(f(theta))
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_rect(self):
        self.assertCEqual(rect(0, 0), (0, 0))
        self.assertCEqual(rect(1, 0), (1., 0))
        self.assertCEqual(rect(1, -pi), (-1., 0))
        self.assertCEqual(rect(1, pi/2), (0, 1.))
        self.assertCEqual(rect(1, -pi/2), (0, -1.))
项目:WXMLTilingsHOWTO    作者:maxieds    | 项目源码 | 文件源码
def get_tiles(self): 

          #radiusR = DEFAULT_RADIUS_R; 
          #triangles = [(COLOR_RED, 0, 4 * radiusR, 4 * radiusR * ((0j-1)**-.2))]
          # Create an initial wheel of red triangles around the origin 
          # (from the comments section of the reference): 
          radiusR = DEFAULT_RADIUS_R; 
          triangles = []
          for i in xrange(10):
               B = cmath.rect(1, (2*i - 1) * math.pi / radiusR)
               C = cmath.rect(1, (2*i + 1) * math.pi / radiusR)
               if i % 2 == 0:
                    B, C = C, B # Make sure to mirror every second triangle
               ##
               triangles.append((COLOR_RED, B, 0j, C)) 
          ##         

          for i in range(self.num_steps):
               triangles = self.subdivide(triangles)

          point_to_vector = lambda pt: Penrose_Tiling.complex_to_vector(pt);

          tile_list = []; 
          for (color, A, B, C) in triangles:
               tile_list.append([point_to_vector(A), point_to_vector(B), point_to_vector(C)]); 
          return tile_list; 

     ## def 

## class
项目:WXMLTilingsHOWTO    作者:maxieds    | 项目源码 | 文件源码
def get_tiles(self): 

          # Create an initial wheel of red triangles around the origin 
          # (from the comments section of the reference): 
          radiusR = DEFAULT_RADIUS_R; 
          triangles = []
          for i in xrange(10):
               B = cmath.rect(1, (2*i - 1) * math.pi / radiusR)
               C = cmath.rect(1, (2*i + 1) * math.pi / radiusR)
               if i % 2 == 0:
                    B, C = C, B # Make sure to mirror every second triangle
               ##
               triangles.append((COLOR_RED, B, 0j, C)) 
          ##

          for i in range(self.num_steps):
               triangles = self.subdivide(triangles)

          point_to_vector = lambda pt: PenroseKD_Tiling.complex_to_vector(pt);

          tile_list = []; 
          for (color, A, B, C) in triangles:
               tile_list.append([point_to_vector(A), point_to_vector(B), \
                                 point_to_vector(C)]); 
          return tile_list; 

     ## def 

## class
项目: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