当前位置: 首页>>代码示例>>Python>>正文


Python cmath.rect方法代码示例

本文整理汇总了Python中cmath.rect方法的典型用法代码示例。如果您正苦于以下问题:Python cmath.rect方法的具体用法?Python cmath.rect怎么用?Python cmath.rect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cmath的用法示例。


在下文中一共展示了cmath.rect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: angle_average

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import rect [as 别名]
def angle_average(angles: np.ndarray) -> float:
    """
    Function to calculate the average value of a list of angles.

    Parameters
    ----------
    angles : numpy.ndarray
        Parallactic angles (deg).

    Returns
    -------
    float
        Average angle (deg).
    """

    cmath_rect = sum(cmath.rect(1, math.radians(ang)) for ang in angles)
    cmath_phase = cmath.phase(cmath_rect/len(angles))

    return math.degrees(cmath_phase) 
开发者ID:PynPoint,项目名称:PynPoint,代码行数:21,代码来源:module.py

示例2: clock

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import rect [as 别名]
def clock(x):
    print('Clock test.')
    refresh(ssd, True)  # Clear any prior image
    lbl = Label(wri, 5, 85, 'Clock')
    dial = Dial(wri, 5, 5, height = 75, ticks = 12, bdcolor=None, label=50)  # Border in fg color
    hrs = Pointer(dial)
    mins = Pointer(dial)
    hrs.value(0 + 0.7j, RED)
    mins.value(0 + 0.9j, YELLOW)
    dm = cmath.rect(1, -cmath.pi/30)  # Rotate by 1 minute (CW)
    dh = cmath.rect(1, -cmath.pi/1800)  # Rotate hours by 1 minute
    for n in range(x):
        refresh(ssd)
        utime.sleep_ms(200)
        mins.value(mins.value() * dm, YELLOW)
        hrs.value(hrs.value() * dh, RED)
        dial.text('ticks: {}'.format(n))
    lbl.value('Done') 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:20,代码来源:color15.py

示例3: arrow

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import rect [as 别名]
def arrow(dev, origin, vec, lc, color, ccw=cmath.exp(3j * cmath.pi/4), cw=cmath.exp(-3j * cmath.pi/4)):
    length, theta = cmath.polar(vec)
    uv = cmath.rect(1, theta)  # Unit rotation vector
    start = -vec
    if length > 3 * lc:  # If line is long
        ds = cmath.rect(lc, theta)
        start += ds  # shorten to allow for length of tail chevrons
    chev = lc + 0j
    polar(dev, origin, vec, color)  # Origin to tip
    polar(dev, origin, start, color)  # Origin to tail
    polar(dev, origin + conj(vec), chev*ccw*uv, color)  # Tip chevron
    polar(dev, origin + conj(vec), chev*cw*uv, color)
    if length > lc:  # Confusing appearance of very short vectors with tail chevron
        polar(dev, origin + conj(start), chev*ccw*uv, color)  # Tail chevron
        polar(dev, origin + conj(start), chev*cw*uv, color)

# If a (framebuf based) device is passed to refresh, the screen is cleared.
# None causes pending widgets to be drawn and the result to be copied to hardware.
# The pend mechanism enables a displayable object to postpone its renedering
# until it is complete: efficient for e.g. Dial which may have multiple Pointers 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:22,代码来源:nanogui.py

示例4: show

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import rect [as 别名]
def show(self):
        super().show()  # Clear working area
        ssd = self.device
        x0 = self.x0
        y0 = self.y0
        radius = self.radius
        adivs = self.adivs
        rdivs = self.rdivs
        diam = 2 * radius
        if rdivs > 0:
            for r in range(1, rdivs + 1):
                circle(ssd, self.xp_origin, self.yp_origin, round(radius * r / rdivs), self.gridcolor)
        if adivs > 0:
            v = complex(1)
            m = rect(1, pi / adivs)
            for _ in range(adivs):
                self.cline(-v, v, self.gridcolor)
                v *= m
        ssd.vline(x0 + radius, y0, diam, self.fgcolor)
        ssd.hline(x0, y0 + radius, diam, self.fgcolor) 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:22,代码来源:fplot.py

示例5: aclock

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import rect [as 别名]
def aclock(dial, lbldate, lbltim):
    uv = lambda phi : rect(1, phi)  # Return a unit vector of phase phi
    days = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
            'Sunday')
    months = ('January', 'February', 'March', 'April', 'May', 'June', 'July',
              'August', 'September', 'October', 'November', 'December')

    hrs = Pointer(dial)
    mins = Pointer(dial)
    secs = Pointer(dial)

    hstart =  0 + 0.7j  # Pointer lengths. Position at top.
    mstart = 0 + 1j
    sstart = 0 + 1j 

    while True:
        t = time.localtime()
        hrs.value(hstart * uv(-t[3] * pi/6 - t[4] * pi / 360), CYAN)
        mins.value(mstart * uv(-t[4] * pi/30), CYAN)
        secs.value(sstart * uv(-t[5] * pi/30), RED)
        lbltim.value('{:02d}.{:02d}.{:02d}'.format(t[3], t[4], t[5]))
        lbldate.value('{} {} {} {}'.format(days[t[6]], t[2], months[t[1] - 1], t[0]))
        await asyncio.sleep(1) 
开发者ID:peterhinch,项目名称:micropython-tft-gui,代码行数:25,代码来源:vtest.py

示例6: show

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import rect [as 别名]
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() 
开发者ID:peterhinch,项目名称:micropython-tft-gui,代码行数:21,代码来源:plot.py

示例7: bezierLength

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import rect [as 别名]
def bezierLength(points, beginT=0, endT=1, samples=1024):
    # https://en.wikipedia.org/wiki/Arc_length#Finding_arc_lengths_by_integrating
    vec = [points[1]-points[0], points[2]-points[1], points[3]-points[2]]
    dot = [vec[0]@vec[0], vec[0]@vec[1], vec[0]@vec[2], vec[1]@vec[1], vec[1]@vec[2], vec[2]@vec[2]]
    factors = [
        dot[0],
        4*(dot[1]-dot[0]),
        6*dot[0]+4*dot[3]+2*dot[2]-12*dot[1],
        12*dot[1]+4*(dot[4]-dot[0]-dot[2])-8*dot[3],
        dot[0]+dot[5]+2*dot[2]+4*(dot[3]-dot[1]-dot[4])
    ]
    # https://en.wikipedia.org/wiki/Trapezoidal_rule
    length = 0
    prev_value = math.sqrt(factors[4]+factors[3]+factors[2]+factors[1]+factors[0])
    for index in range(0, samples+1):
        t = beginT+(endT-beginT)*index/samples
        # value = math.sqrt(factors[4]*(t**4)+factors[3]*(t**3)+factors[2]*(t**2)+factors[1]*t+factors[0])
        value = math.sqrt((((factors[4]*t+factors[3])*t+factors[2])*t+factors[1])*t+factors[0])
        length += (prev_value+value)*0.5
        prev_value = value
    return length*3/samples

# https://en.wikipedia.org/wiki/Root_of_unity
# cubic_roots_of_unity = [cmath.rect(1, i/3*2*math.pi) for i in range(0, 3)] 
开发者ID:Lichtso,项目名称:curve_cad,代码行数:26,代码来源:internal.py

示例8: ticks

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import rect [as 别名]
def ticks(hrs, length):
    vs = rect(RADIUS, PHI)  # Coords relative to arc origin
    ve = rect(RADIUS - length, PHI)  # Short tick
    ve1 = rect(RADIUS - 1.5 * length, PHI)  # Long tick
    ve2 = rect(RADIUS - 2.0 * length, PHI)  # Extra long tick
    rv = rect(1, -5 * RV)  # Rotation vector for 5 minutes (about OR)
    rot = rect(1, (3 - hrs) * pi / 6)  # hrs rotation (about [0,0])
    for n in range(13):
        # Translate to 0, 0
        if n == 6:  # Overdrawn by hour pointer: visually cleaner if we skip
            yield
        elif n % 3 == 0:
            yield ((vs + XLT) * rot, (ve2 + XLT) * rot)  # Extra Long
        elif n % 2 == 0:
            yield ((vs + XLT) * rot, (ve1 + XLT) * rot)  # Long
        else:
            yield ((vs + XLT) * rot, (ve + XLT) * rot)  # Short
        vs *= rv
        ve *= rv
        ve1 *= rv
        ve2 *= rv

# Generate vectors for the hour chevron 
开发者ID:peterhinch,项目名称:micropython-epaper,代码行数:25,代码来源:newclock.py

示例9: test_rect

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import rect [as 别名]
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.)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_cmath.py

示例10: compass

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import rect [as 别名]
def compass(x):
    print('Compass test.')
    refresh(ssd, True)  # Clear any prior image
    dial = Dial(wri, 5, 5, height = 75, bdcolor=None, label=50, style = Dial.COMPASS)
    bearing = Pointer(dial)
    bearing.value(0 + 1j, RED)
    dh = cmath.rect(1, -cmath.pi/30)  # Rotate by 6 degrees CW
    for n in range(x):
        utime.sleep_ms(200)
        bearing.value(bearing.value() * dh, RED)
        refresh(ssd) 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:13,代码来源:color15.py

示例11: show

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import rect [as 别名]
def show(self):
        wri = self.writer
        dev = self.device
        dev.fill_rect(self.col, self.row, self.width, self.height, self.bgcolor)
        if isinstance(self.bdcolor, bool):  # No border
            if self.has_border:  # Border exists: erase it
                dev.rect(self.col - 2, self.row - 2, self.width + 4, self.height + 4, self.bgcolor)
                self.has_border = False
        elif self.bdcolor:  # Border is required
            dev.rect(self.col - 2, self.row - 2, self.width + 4, self.height + 4, self.bdcolor)
            self.has_border = True 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:13,代码来源:nanogui.py

示例12: polar_clip

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import rect [as 别名]
def polar_clip():
    print('Test of polar data clipping.')
    def populate(rot):
        f = lambda theta : cmath.rect(1.15 * math.sin(5 * theta), theta) * rot # complex
        nmax = 150
        for n in range(nmax + 1):
            yield f(2 * cmath.pi * n / nmax)  # complex z
    refresh(ssd, True)  # Clear any prior image
    g = PolarGraph(wri, 2, 2, fgcolor=WHITE, gridcolor=LIGHTGREEN)
    curve = PolarCurve(g, YELLOW, populate(1))
    curve1 = PolarCurve(g, RED, populate(cmath.rect(1, cmath.pi/5),))
    refresh(ssd) 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:14,代码来源:fpt.py

示例13: rt_polar

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import rect [as 别名]
def rt_polar():
    print('Simulate realtime polar data acquisition.')
    refresh(ssd, True)  # Clear any prior image
    g = PolarGraph(wri, 2, 2, fgcolor=WHITE, gridcolor=LIGHTGREEN)
    curvey = PolarCurve(g, YELLOW)
    curver = PolarCurve(g, RED)
    for x in range(100):
        curvey.point(cmath.rect(x/100, -x * cmath.pi/30))
        curver.point(cmath.rect((100 - x)/100, -x * cmath.pi/30))
        utime.sleep_ms(60)
        refresh(ssd) 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:13,代码来源:fpt.py

示例14: aclock

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import rect [as 别名]
def aclock():
    uv = lambda phi : cmath.rect(1, phi)  # Return a unit vector of phase phi
    pi = cmath.pi
    days = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
            'Sunday')
    months = ('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July',
              'Aug', 'Sept', 'Oct', 'Nov', 'Dec')
    # Instantiate CWriter
    CWriter.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
    wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False)
    wri.set_clip(True, True, False)

    # Instantiate displayable objects
    dial = Dial(wri, 2, 2, height = 75, ticks = 12, bdcolor=None, label=120, pip=False)  # Border in fg color
    lbltim = Label(wri, 5, 85, 35)
    hrs = Pointer(dial)
    mins = Pointer(dial)
    secs = Pointer(dial)

    hstart =  0 + 0.7j  # Pointer lengths and position at top
    mstart = 0 + 0.92j
    sstart = 0 + 0.92j 
    while True:
        t = utime.localtime()
        hrs.value(hstart * uv(-t[3]*pi/6 - t[4]*pi/360), YELLOW)
        mins.value(mstart * uv(-t[4] * pi/30), YELLOW)
        secs.value(sstart * uv(-t[5] * pi/30), RED)
        lbltim.value('{:02d}.{:02d}.{:02d}'.format(t[3], t[4], t[5]))
        dial.text('{} {} {} {}'.format(days[t[6]], t[2], months[t[1] - 1], t[0]))
        refresh(ssd)
        utime.sleep(1) 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:33,代码来源:aclock.py

示例15: _append_line_data

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import rect [as 别名]
def _append_line_data(self, freq: int, data: list):
        data_list = iter(self.sdata)
        vals = iter(data)
        for v in vals:
            if self.opts.format == "ri":
                next(data_list).append(Datapoint(freq, float(v), float(next(vals))))
            if self.opts.format == "ma":
                z = cmath.rect(float(v), math.radians(float(next(vals))))
                next(data_list).append(Datapoint(freq, z.real, z.imag))
            if self.opts.format == "db":
                z = cmath.rect(10 ** (float(v) / 20), math.radians(float(next(vals))))
                next(data_list).append(Datapoint(freq, z.real, z.imag)) 
开发者ID:NanoVNA-Saver,项目名称:nanovna-saver,代码行数:14,代码来源:Touchstone.py


注:本文中的cmath.rect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。