本文整理汇总了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
示例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
示例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
示例6: test_polar
# 需要导入模块: import cmath [as 别名]
# 或者: from cmath import polar [as 别名]
def test_polar(self):
self.check_polar(polar)
示例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)
示例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)
示例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
示例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)
示例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))
示例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)
示例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