當前位置: 首頁>>代碼示例>>Python>>正文


Python cmath.polar方法代碼示例

本文整理匯總了Python中cmath.polar方法的典型用法代碼示例。如果您正苦於以下問題:Python cmath.polar方法的具體用法?Python cmath.polar怎麽用?Python cmath.polar使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cmath的用法示例。


在下文中一共展示了cmath.polar方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: fillcircle

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import polar [as 別名]
def fillcircle(dev, x0, y0, r, color): # Draw filled circle
    x0, y0, r = int(x0), int(y0), int(r)
    x = -r
    y = 0
    err = 2 -2*r
    while x <= 0:
        dev.line(x0 -x, y0 -y, x0 -x, y0 +y, color)
        dev.line(x0 +x, y0 -y, x0 +x, y0 +y, color)
        e2 = err
        if (e2 <= y):
            y +=1
            err += y*2 +1
            if (-x == y and e2 <= x):
                e2 = 0
        if (e2 > x):
            x += 1
            err += x*2 +1

# Line defined by polar coords; origin and line are complex 
開發者ID:peterhinch,項目名稱:micropython-nano-gui,代碼行數:21,代碼來源:nanogui.py

示例2: arrow

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import polar [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: draw_star

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import polar [as 別名]
def draw_star(self):
        dx = self.end_x - self.start_x
        dy = self.end_y - self.start_y
        z = complex(dx, dy)
        radius_out, angle0 = cmath.polar(z)
        radius_in = radius_out / 2 # this ratio is called the spoke ratio and can also be configured by user
        points = list()
        for edge in range(self.number_of_spokes):
            # outer circle angle
            angle = angle0 + edge * (2 * math.pi) / self.number_of_spokes
            # x coordinate (outer circle)
            points.append(self.start_x + radius_out * math.cos(angle))
            # y coordinate (outer circle)
            points.append(self.start_y + radius_out * math.sin(angle))
            # inner circle angle
            angle += math.pi / self.number_of_spokes
            # x coordinate (inner circle)
            points.append(self.start_x + radius_in * math.cos(angle))
            # y coordinate (inner circle)
            points.append(self.start_y + radius_in * math.sin(angle))
        self.current_item = self.canvas.create_polygon(
            points, outline=self.outline, fill=self.fill,
            width=self.width) 
開發者ID:PacktPublishing,項目名稱:Tkinter-GUI-Application-Development-Blueprints-Second-Edition,代碼行數:25,代碼來源:6.04.py

示例4: draw_star

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import polar [as 別名]
def draw_star(self):
        dx = self.end_x - self.start_x
        dy = self.end_y - self.start_y
        z = complex(dx, dy)
        radius_out, angle0 = cmath.polar(z)
        radius_in = radius_out / 2
        points = list()
        for edge in range(self.number_of_spokes):
            angle = angle0 + edge * (2 * math.pi) / self.number_of_spokes
            points.append(self.start_x + radius_out * math.cos(angle))
            points.append(self.start_y + radius_out * math.sin(angle))
            angle += math.pi / self.number_of_spokes
            points.append(self.start_x + radius_in * math.cos(angle))
            points.append(self.start_y + radius_in * math.sin(angle))
        self.current_item = self.canvas.create_polygon(
            points, outline=self.outline, fill=self.fill,
            width=self.width) 
開發者ID:PacktPublishing,項目名稱:Tkinter-GUI-Application-Development-Blueprints-Second-Edition,代碼行數:19,代碼來源:6.05.py

示例5: arrow

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import polar [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_polar

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import polar [as 別名]
def test_polar(self):
        self.check_polar(polar) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:4,代碼來源:test_cmath.py

示例7: test_polar_errno

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import polar [as 別名]
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) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,代碼來源:test_cmath.py

示例8: polar

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import polar [as 別名]
def polar(dev, origin, line, color):
    xs, ys = origin.real, origin.imag
    theta = cmath.polar(line)[1]
    dev.line(round(xs), round(ys), round(xs + line.real), round(ys - line.imag), color) 
開發者ID:peterhinch,項目名稱:micropython-nano-gui,代碼行數:6,代碼來源:nanogui.py

示例9: value

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import polar [as 別名]
def value(self, v=None, color=None):
        self.color = color
        if v is not None:
            if isinstance(v, complex):
                l = cmath.polar(v)[0]
                if l > 1:
                    self.val = v/l
                else:
                    self.val = v
            else:
                raise ValueError('Pointer value must be complex.')
        self.dial.vectors.add(self)
        self.dial._set_pend(self.dial)  # avoid redrawing for each vector
        return self.val 
開發者ID:peterhinch,項目名稱:micropython-nano-gui,代碼行數:16,代碼來源:nanogui.py

示例10: show

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import polar [as 別名]
def show(self):
        super().show()
        # cache bound variables
        dev = self.device
        ticks = self.ticks
        radius = self.radius
        xo = self.xorigin
        yo = self.yorigin
        # vectors (complex)
        vor = xo + 1j * yo
        vtstart = 0.9 * radius + 0j  # start of tick
        vtick = 0.1 * radius + 0j  # tick
        vrot = cmath.exp(2j * cmath.pi/ticks)  # unit rotation
        for _ in range(ticks):
            polar(dev, vor + conj(vtstart), vtick, self.fgcolor)
            vtick *= vrot
            vtstart *= vrot
        circle(dev, xo, yo, radius, self.fgcolor)
        vshort = 1000  # Length of shortest vector
        for v in self.vectors:
            color = self.fgcolor if v.color is None else v.color
            val = v.value() * radius  # val is complex
            vshort = min(vshort, cmath.polar(val)[0])
            if self.style == Dial.CLOCK:
                polar(dev, vor, val, color)
            else:
                arrow(dev, vor, val, 5, color)
        if isinstance(self.pip, int) and vshort > 5:
            fillcircle(dev, xo, yo, 2, self.pip) 
開發者ID:peterhinch,項目名稱:micropython-nano-gui,代碼行數:31,代碼來源:nanogui.py

示例11: test_polar

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import polar [as 別名]
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)) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:8,代碼來源:test_cmath.py

示例12: draw_triangle

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import polar [as 別名]
def draw_triangle(self):
        dx = self.end_x - self.start_x
        dy = self.end_y - self.start_y
        z = complex(dx, dy)
        radius, angle0 = cmath.polar(z)
        edges = 3   # nb of edges in circle
        points = list()
        for edge in range(edges):
            angle = angle0 + edge * (2 * math.pi) / edges
            points.append(self.start_x + radius * math.cos(angle)) # x coordinate
            points.append(self.start_y + radius * math.sin(angle)) # y coordinate
        self.current_item = self.canvas.create_polygon(
            points, outline=self.outline, fill=self.fill,
            width=self.width) 
開發者ID:PacktPublishing,項目名稱:Tkinter-GUI-Application-Development-Blueprints-Second-Edition,代碼行數:16,代碼來源:6.04.py

示例13: draw_triangle

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import polar [as 別名]
def draw_triangle(self):
        dx = self.end_x - self.start_x
        dy = self.end_y - self.start_y
        z = complex(dx, dy)
        radius, angle0 = cmath.polar(z)
        edges = 3
        points = list()
        for edge in range(edges):
            angle = angle0 + edge * (2 * math.pi) / edges
            points.append(self.start_x + radius * math.cos(angle))
            points.append(self.start_y + radius * math.sin(angle))
        self.current_item = self.canvas.create_polygon(
            points, outline=self.outline, fill=self.fill,
            width=self.width) 
開發者ID:PacktPublishing,項目名稱:Tkinter-GUI-Application-Development-Blueprints-Second-Edition,代碼行數:16,代碼來源:6.05.py

示例14: myangle

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import polar [as 別名]
def myangle(self, a, b):  # 返回向量a,b的夾角,a->b逆時針為正(-pi~pi)
        ac = complex(a[0], a[1])
        bc = complex(b[0], b[1])
        alpha = float((cmath.polar(ac))[1])
        beta = float((cmath.polar(bc))[1])
        return (alpha - beta) 
開發者ID:chbpku,項目名稱:osmo.sessdsa,代碼行數:8,代碼來源:F-Bravo.py

示例15: __pow__

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import polar [as 別名]
def __pow__(self, power):
        if power == 1:
            return self
        if power == -1:
            return PauliString(qubit_pauli_map=self._qubit_pauli_map,
                               coefficient=self.coefficient**-1)
        if isinstance(power, (int, float)):
            r, i = cmath.polar(self.coefficient)
            if abs(r - 1) > 0.0001:
                # Raising non-unitary PauliStrings to a power is not supported.
                return NotImplemented

            if len(self) == 1:
                q, p = next(iter(self.items()))
                gates = {
                    pauli_gates.X: common_gates.XPowGate,
                    pauli_gates.Y: common_gates.YPowGate,
                    pauli_gates.Z: common_gates.ZPowGate,
                }
                return gates[p](exponent=power).on(q)

            global_half_turns = power * (i / math.pi)

            # HACK: Avoid circular dependency.
            from cirq.ops import pauli_string_phasor
            return pauli_string_phasor.PauliStringPhasor(
                PauliString(qubit_pauli_map=self._qubit_pauli_map),
                exponent_neg=global_half_turns + power,
                exponent_pos=global_half_turns)
        return NotImplemented 
開發者ID:quantumlib,項目名稱:Cirq,代碼行數:32,代碼來源:pauli_string.py


注:本文中的cmath.polar方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。