Python cmath.polar() Examples
The following are 30
code examples of cmath.polar().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cmath
, or try the search function
.
Example #1
Source File: vectors.py From micropython-tft-gui with MIT License | 6 votes |
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
Example #2
Source File: 6.08.py From Tkinter-GUI-Application-Development-Blueprints-Second-Edition with MIT License | 6 votes |
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)
Example #3
Source File: 6.09.py From Tkinter-GUI-Application-Development-Blueprints-Second-Edition with MIT License | 6 votes |
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)
Example #4
Source File: 6.05.py From Tkinter-GUI-Application-Development-Blueprints-Second-Edition with MIT License | 6 votes |
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)
Example #5
Source File: 6.04.py From Tkinter-GUI-Application-Development-Blueprints-Second-Edition with MIT License | 6 votes |
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)
Example #6
Source File: nanogui.py From micropython-nano-gui with MIT License | 6 votes |
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
Example #7
Source File: nanogui.py From micropython-nano-gui with MIT License | 6 votes |
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
Example #8
Source File: test_cmath.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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))
Example #9
Source File: test_cmath.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #10
Source File: test_cmath.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_polar(self): self.check_polar(polar)
Example #11
Source File: vectors.py From micropython-tft-gui with MIT License | 5 votes |
def show(self): # cache bound variables tft = self.tft ticks = self.ticks radius = self.radius xo = self.xorigin yo = self.yorigin vor = self.vor if self.redraw: # An overlaying screen has closed. Force redraw. self.redraw = False self.drawn = False if not self.drawn: self.drawn = True vtstart = (1 - self.TICKLEN) * radius + 0j # start of tick vtick = self.TICKLEN * radius + 0j # tick vrot = cmath.exp(2j * cmath.pi/ticks) # unit rotation for _ in range(ticks): pline(tft, vor + conj(vtstart), vtick, self.fgcolor) vtick *= vrot vtstart *= vrot tft.draw_circle(xo, yo, radius, self.fgcolor) vshort = 1000 # Length of shortest vector for v in self.vectors: val = v.value() * radius # val is complex vshort = min(vshort, cmath.polar(val)[0]) v.show() if isinstance(self.pip, tuple) and vshort > 9: tft.fill_circle(xo, yo, 3, self.pip)
Example #12
Source File: vectors.py From micropython-tft-gui with MIT License | 5 votes |
def value(self, v=None, color=None): if isinstance(color, tuple): self.color = color dial = self.dial if v is not None: if isinstance(v, complex): l = cmath.polar(v)[0] newval = v /l if l > 1 else v # Max length = 1.0 else: raise ValueError('Pointer value must be complex.') if v != self.val and dial.screen is Screen.current_screen: self.show(newval) self.val = newval dial.show_if_current() return self.val
Example #13
Source File: test_cmath.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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))
Example #14
Source File: test_cmath.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
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))
Example #15
Source File: pauli_string.py From Cirq with Apache License 2.0 | 5 votes |
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
Example #16
Source File: round_trk.py From RF-tools-KiCAD with GNU General Public License v3.0 | 5 votes |
def create_round_segments(pcb,sp,a1,ep,a2,cntr,rad,layer,width,Nn,N_SEGMENTS): start_point = sp end_point = ep pos = sp next_pos = ep a1 = getAngleRadians(cntr,sp) a2 = getAngleRadians(cntr,ep) wxLogDebug('a1:'+str(math.degrees(a1))+' a2:'+str(math.degrees(a2))+' a2-a1:'+str(math.degrees(a2-a1)),debug) if (a2-a1) > 0 and abs(a2-a1) > math.radians(180): deltaA = -(math.radians(360)-(a2-a1))/N_SEGMENTS wxLogDebug('deltaA reviewed:'+str(math.degrees(deltaA)),debug) elif (a2-a1) < 0 and abs(a2-a1) > math.radians(180): deltaA = (math.radians(360)-abs(a2-a1))/N_SEGMENTS wxLogDebug('deltaA reviewed2:'+str(math.degrees(deltaA)),debug) else: deltaA = (a2-a1)/N_SEGMENTS delta=deltaA wxLogDebug('delta:'+str(math.degrees(deltaA))+' radius:'+str(ToMM(rad)),debug) points = [] #import round_trk; import importlib; importlib.reload(round_trk) for ii in range (N_SEGMENTS+1): #+1): points.append(pos) #t = create_Track(pos,pos) prv_pos = pos #pos = pos + fraction_delta #posPolar = cmath.polar(pos) #(rad) * cmath.exp(math.radians(deltaA)*1j) #cmath.rect(r, phi) : Return the complex number x with polar coordinates r and phi. #pos = wxPoint(posPolar.real+sp.x,posPolar.imag+sp.y) pos = rotatePoint(rad,a1,delta,cntr) delta=delta+deltaA wxLogDebug("pos:"+str(ToUnits(prv_pos.x))+":"+str(ToUnits(prv_pos.y))+";"+str(ToUnits(pos.x))+":"+str(ToUnits(pos.y)),debug) for i, p in enumerate(points): #if i < len (points)-1: if i < len (points)-2: t = create_Track(pcb,p,points[i+1],layer,width,Nn,True) #adding ts code to segments t = create_Track(pcb,points[-2],ep,layer,width,Nn,True) #avoiding rounding on last segment return points[-1] #
Example #17
Source File: F-Bravo.py From osmo.sessdsa with GNU General Public License v3.0 | 5 votes |
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)
Example #18
Source File: test_cmath.py From ironpython3 with Apache License 2.0 | 5 votes |
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)
Example #19
Source File: test_cmath.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_polar(self): self.check_polar(polar)
Example #20
Source File: test_cmath.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_polar(self): self.check_polar(polar)
Example #21
Source File: 6.07.py From Tkinter-GUI-Application-Development-Blueprints-Second-Edition with MIT License | 5 votes |
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)
Example #22
Source File: 6.08.py From Tkinter-GUI-Application-Development-Blueprints-Second-Edition with MIT License | 5 votes |
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)
Example #23
Source File: 6.09.py From Tkinter-GUI-Application-Development-Blueprints-Second-Edition with MIT License | 5 votes |
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)
Example #24
Source File: 6.06.py From Tkinter-GUI-Application-Development-Blueprints-Second-Edition with MIT License | 5 votes |
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)
Example #25
Source File: 6.05.py From Tkinter-GUI-Application-Development-Blueprints-Second-Edition with MIT License | 5 votes |
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)
Example #26
Source File: 6.04.py From Tkinter-GUI-Application-Development-Blueprints-Second-Edition with MIT License | 5 votes |
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)
Example #27
Source File: test_cmath.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #28
Source File: test_cmath.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_polar(self): self.check_polar(polar)
Example #29
Source File: test_cmath.py From oss-ftp with MIT License | 5 votes |
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))
Example #30
Source File: test_cmath.py From BinderFilter with MIT License | 5 votes |
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))