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


Python cmath.pi方法代码示例

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


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

示例1: clock

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import pi [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

示例2: arrow

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import pi [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

示例3: show

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import pi [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

示例4: aclock

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import pi [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

示例5: arrow

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import pi [as 别名]
def arrow(tft, origin, vec, lc, color):
    ccw = cmath.exp(3j * cmath.pi/4)  # Unit vectors
    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
    pline(tft, origin, vec, color)  # Origin to tip
    pline(tft, origin, start, color)  # Origin to tail
    pline(tft, origin + conj(vec), chev*ccw*uv, color)  # Tip chevron
    pline(tft, origin + conj(vec), chev*cw*uv, color)
    if length > lc:  # Confusing appearance of very short vectors with tail chevron
        pline(tft, origin + conj(start), chev*ccw*uv, color)  # Tail chevron
        pline(tft, origin + conj(start), chev*cw*uv, color)

# Vector display 
开发者ID:peterhinch,项目名称:micropython-tft-gui,代码行数:21,代码来源:vectors.py

示例6: test_tauegamma_implementation

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import pi [as 别名]
def test_tauegamma_implementation(self):
        input_dict_list=[{
        'Cgamma_mue':np.random.random()*1e-8*exp(1j*2*pi*np.random.random()),
        'Cgamma_emu':np.random.random()*1e-8*exp(1j*2*pi*np.random.random()),
        } for i in range(10)]
        BRs = np.array([
            flavio.np_prediction(
                'BR(mu->egamma)',
                Wilson(input_dict, 100,  'WET', 'flavio')
            )
            for input_dict in input_dict_list
        ])
        compare_BRs = np.array([
            compare_BR(
                Wilson(input_dict, 100,  'WET', 'flavio'),
                'mu', 'e',
            )
            for input_dict in input_dict_list
        ])
        self.assertAlmostEqual(np.max(np.abs(1-BRs/compare_BRs)), 0, delta=0.005) 
开发者ID:flav-io,项目名称:flavio,代码行数:22,代码来源:test_muegamma.py

示例7: compare_BR

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import pi [as 别名]
def compare_BR(wc_wilson, l1, l2):
    scale = flavio.config['renormalization scale'][l1+'decays']
    ll = wcxf_sector_names[l1, l2]
    par = flavio.default_parameters.get_central_all()
    wc_obj = flavio.WilsonCoefficients.from_wilson(wc_wilson, par)
    par = flavio.parameters.default_parameters.get_central_all()
    wc = wc_obj.get_wc(ll, scale, par, nf_out=4)
    alpha = flavio.physics.running.running.get_alpha_e(par, scale, nf_out=4)
    e = sqrt(4 * pi * alpha)
    ml = par['m_' + l1]
    # cf. (18) of hep-ph/0404211
    pre = 48 * pi**3 * alpha / par['GF']**2
    DL = 2 / (e * ml) * wc['Cgamma_' + l1 + l2]
    DR = 2 / (e * ml) * wc['Cgamma_' + l2 + l1].conjugate()
    if l1 == 'tau':
        BR_SL = par['BR(tau->{}nunu)'.format(l2)]
    else:
        BR_SL = 1  # BR(mu->enunu) = 1
    return pre * (abs(DL)**2 + abs(DR)**2) * BR_SL 
开发者ID:flav-io,项目名称:flavio,代码行数:21,代码来源:test_taulgamma.py

示例8: test_taumugamma_implementation

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import pi [as 别名]
def test_taumugamma_implementation(self):
        input_dict_list=[{
        'Cgamma_taumu':np.random.random()*1e-8*exp(1j*2*pi*np.random.random()),
        'Cgamma_mutau':np.random.random()*1e-8*exp(1j*2*pi*np.random.random()),
        } for i in range(10)]
        BRs = np.array([
            flavio.np_prediction(
                'BR(tau->mugamma)',
                Wilson(input_dict, 100,  'WET', 'flavio')
            )
            for input_dict in input_dict_list
        ])
        compare_BRs = np.array([
            compare_BR(
                Wilson(input_dict, 100,  'WET', 'flavio'),
                'tau', 'mu',
            )
            for input_dict in input_dict_list
        ])
        self.assertAlmostEqual(np.max(np.abs(1-BRs/compare_BRs)), 0, delta=0.02) 
开发者ID:flav-io,项目名称:flavio,代码行数:22,代码来源:test_taulgamma.py

示例9: test_tauegamma_implementation

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import pi [as 别名]
def test_tauegamma_implementation(self):
        input_dict_list=[{
        'Cgamma_taue':np.random.random()*1e-8*exp(1j*2*pi*np.random.random()),
        'Cgamma_etau':np.random.random()*1e-8*exp(1j*2*pi*np.random.random()),
        } for i in range(10)]
        BRs = np.array([
            flavio.np_prediction(
                'BR(tau->egamma)',
                Wilson(input_dict, 100,  'WET', 'flavio')
            )
            for input_dict in input_dict_list
        ])
        compare_BRs = np.array([
            compare_BR(
                Wilson(input_dict, 100,  'WET', 'flavio'),
                'tau', 'e',
            )
            for input_dict in input_dict_list
        ])
        self.assertAlmostEqual(np.max(np.abs(1-BRs/compare_BRs)), 0, delta=0.002) 
开发者ID:flav-io,项目名称:flavio,代码行数:22,代码来源:test_taulgamma.py

示例10: fft

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import pi [as 别名]
def fft(x):
    N = len(x)
    if N <= 1: return x
    even = fft(x[0::2])
    odd =  fft(x[1::2])
    T= [exp(-2j*pi*k/N)*odd[k] for k in range(N//2)]
    return [even[k] + T[k] for k in range(N//2)] + [even[k] - T[k] for k in range(N//2)] 
开发者ID:PacktPublishing,项目名称:Mastering-IPython-4,代码行数:9,代码来源:fft.py

示例11: test_constants

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import pi [as 别名]
def test_constants(self):
        e_expected = 2.71828182845904523536
        pi_expected = 3.14159265358979323846
        self.assertAlmostEqual(cmath.pi, pi_expected, places=9,
            msg="cmath.pi is {}; should be {}".format(cmath.pi, pi_expected))
        self.assertAlmostEqual(cmath.e, e_expected, places=9,
            msg="cmath.e is {}; should be {}".format(cmath.e, e_expected)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_cmath.py

示例12: check_polar

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import pi [as 别名]
def check_polar(self, func):
        def check(arg, expected):
            got = func(arg)
            for e, g in zip(expected, got):
                self.rAssertAlmostEqual(e, g)
        check(0, (0., 0.))
        check(1, (1., 0.))
        check(-1, (1., pi))
        check(1j, (1., pi / 2))
        check(-3j, (3., -pi / 2))
        inf = float('inf')
        check(complex(inf, 0), (inf, 0.))
        check(complex(-inf, 0), (inf, pi))
        check(complex(3, inf), (inf, pi / 2))
        check(complex(5, -inf), (inf, -pi / 2))
        check(complex(inf, inf), (inf, pi / 4))
        check(complex(inf, -inf), (inf, -pi / 4))
        check(complex(-inf, inf), (inf, 3 * pi / 4))
        check(complex(-inf, -inf), (inf, -3 * pi / 4))
        nan = float('nan')
        check(complex(nan, 0), (nan, nan))
        check(complex(0, nan), (nan, nan))
        check(complex(nan, nan), (nan, nan))
        check(complex(inf, nan), (inf, nan))
        check(complex(-inf, nan), (inf, nan))
        check(complex(nan, inf), (inf, nan))
        check(complex(nan, -inf), (inf, nan)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:29,代码来源:test_cmath.py

示例13: test_phase

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import pi [as 别名]
def test_phase(self):
        self.assertAlmostEqual(phase(0), 0.)
        self.assertAlmostEqual(phase(1.), 0.)
        self.assertAlmostEqual(phase(-1.), pi)
        self.assertAlmostEqual(phase(-1.+1E-300j), pi)
        self.assertAlmostEqual(phase(-1.-1E-300j), -pi)
        self.assertAlmostEqual(phase(1j), pi/2)
        self.assertAlmostEqual(phase(-1j), -pi/2)

        # zeros
        self.assertEqual(phase(complex(0.0, 0.0)), 0.0)
        self.assertEqual(phase(complex(0.0, -0.0)), -0.0)
        self.assertEqual(phase(complex(-0.0, 0.0)), pi)
        self.assertEqual(phase(complex(-0.0, -0.0)), -pi)

        # infinities
        self.assertAlmostEqual(phase(complex(-INF, -0.0)), -pi)
        self.assertAlmostEqual(phase(complex(-INF, -2.3)), -pi)
        self.assertAlmostEqual(phase(complex(-INF, -INF)), -0.75*pi)
        self.assertAlmostEqual(phase(complex(-2.3, -INF)), -pi/2)
        self.assertAlmostEqual(phase(complex(-0.0, -INF)), -pi/2)
        self.assertAlmostEqual(phase(complex(0.0, -INF)), -pi/2)
        self.assertAlmostEqual(phase(complex(2.3, -INF)), -pi/2)
        self.assertAlmostEqual(phase(complex(INF, -INF)), -pi/4)
        self.assertEqual(phase(complex(INF, -2.3)), -0.0)
        self.assertEqual(phase(complex(INF, -0.0)), -0.0)
        self.assertEqual(phase(complex(INF, 0.0)), 0.0)
        self.assertEqual(phase(complex(INF, 2.3)), 0.0)
        self.assertAlmostEqual(phase(complex(INF, INF)), pi/4)
        self.assertAlmostEqual(phase(complex(2.3, INF)), pi/2)
        self.assertAlmostEqual(phase(complex(0.0, INF)), pi/2)
        self.assertAlmostEqual(phase(complex(-0.0, INF)), pi/2)
        self.assertAlmostEqual(phase(complex(-2.3, INF)), pi/2)
        self.assertAlmostEqual(phase(complex(-INF, INF)), 0.75*pi)
        self.assertAlmostEqual(phase(complex(-INF, 2.3)), pi)
        self.assertAlmostEqual(phase(complex(-INF, 0.0)), pi)

        # real or imaginary part NaN
        for z in complex_nans:
            self.assertTrue(math.isnan(phase(z))) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:42,代码来源:test_cmath.py

示例14: test_rect

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import pi [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

示例15: compass

# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import pi [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


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