python类rect()的实例源码

plot.py 文件源码 项目:micropython-tft-gui 作者: peterhinch 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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()
lplot.py 文件源码 项目:micropython-lcd160cr-gui 作者: peterhinch 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
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.py 文件源码 项目:QuickJoint 作者: JarrettR 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def draw_parallel(self, start, guideLine, stepDistance):
        polR, polPhi = cmath.polar(guideLine)
        polR = stepDistance
        return (cmath.rect(polR, polPhi) + start)
quickjoint.py 文件源码 项目:QuickJoint 作者: JarrettR 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
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)
tool.py 文件源码 项目:CON-SAI 作者: SSL-Roots 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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
pt.py 文件源码 项目:micropython-tft-gui 作者: peterhinch 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
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
pt.py 文件源码 项目:micropython-tft-gui 作者: peterhinch 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
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))
pt.py 文件源码 项目:micropython-tft-gui 作者: peterhinch 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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.
test_cmath.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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.))
navigation.py 文件源码 项目:SCOUT 作者: johngroves 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
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))
visual.py 文件源码 项目:tk_tools 作者: slightlynybbled 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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)
visual.py 文件源码 项目:tk_tools 作者: slightlynybbled 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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
            )
visual.py 文件源码 项目:tk_tools 作者: slightlynybbled 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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)
test_cmath.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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.))
test_cmath.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
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.))
time_tools.py 文件源码 项目:mh370_sat_tools 作者: kprostyakov 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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
test_cmath.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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.))
data.py 文件源码 项目:PhasorToolBox 作者: sonusz 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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
data.py 文件源码 项目:PhasorToolBox 作者: sonusz 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
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
data.py 文件源码 项目:PhasorToolBox 作者: sonusz 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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
data.py 文件源码 项目:PhasorToolBox 作者: sonusz 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
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
average3.py 文件源码 项目:picasso 作者: jungmannlab 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def mean_angle(self, deg):
        return (phase(sum(rect(1, d) for d in deg)/len(deg)))
kiwifax.py 文件源码 项目:kiwiclient 作者: dev-zzo 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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)
test_cmath.py 文件源码 项目:pefile.pypy 作者: cloudtracer 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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.))
test_cmath.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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.))
test_cmath.py 文件源码 项目:ndk-python 作者: gittor 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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.))
lpt.py 文件源码 项目:micropython-lcd160cr-gui 作者: peterhinch 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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
lpt.py 文件源码 项目:micropython-lcd160cr-gui 作者: peterhinch 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
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))
lpt.py 文件源码 项目:micropython-lcd160cr-gui 作者: peterhinch 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
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))
test_cmath.py 文件源码 项目:kbe_server 作者: xiaohaoppy 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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.))


问题


面经


文章

微信
公众号

扫码关注公众号