def shapecontains(shape, pos): sx, sy = shape["pos"] theta = math.atan2(sx, sy) if sx or sy else 0 dx, dy = math.R(theta, pos) dy -= math.length((sx, sy)) if shape["type"] == "circle": return math.length(dx, dy) <= shape["r"] if shape["type"] == "shard": sw, sh = shape["size"] return abs(dx / sw) + abs(dy / sh) < 1 if shape["type"] == "blade": w = shape["width"] dx = abs(dx / w) dy /= 4 * w return (dy < 0 and dx < 1) or (dy >= 0 and dx + dy < 1)
def addpoint(pos): x, y = view.FconvertB(Fspot1, pos) r = math.length((x, y)) na = 12 / math.tau * math.atan2(x, y) n, a = divmod(na, 1) n = int(n) if n % 2 == 1: a = 1 - a a = round(a, 3) r = round(r, 3) data = a, r, n if n % 2 == 1: a = 1 - a C, S = math.CS((n + a) / 12 * math.tau, r) pF = S, C covered = iscovered(pF) if covered: self.ydata += [data] self.yespoints += [pF] else: self.ndata += [data] self.nopoints += [pF] print() print([self.ydata, self.ndata]) checkcover()
def polygon(self, f=1): key = self.pos, self.width, f if key == self.cpolygonkey: return self.cpolygon s = math.length(self.pos) x, y = self.pos x0 = self.width y0 = 2 / math.tan(math.radians(30)) * self.width beta = math.atan2(x - x0, y - y0) gamma = 4 * beta - math.tau / 8 ds = beta / (math.tau / 12) # 0 on left 1 on right s0 = (1 - 0.4 * ds) * s d = (0.2 * ds**2) * s p0 = -0.02, s0 p1 = d, s0 C, S = math.CS(gamma + 3 / 8 * math.tau, d) p2 = x + C, y - S p3 = self.pos ps = bezier([p0, p1, p2, p3]) s1 = (1 - 0.4 * (1 - ds)) * s d = (0.2 * (1 - ds)**2) * s p0 = s1 * S30 + 0.02 * C30, s1 * C30 - 0.02 * S30 p1 = s1 * S30 - d * C30, s1 * C30 + d * S30 C, S = math.CS(gamma + 3 / 8 * math.tau, d) p2 = x + S, y + C p3 = self.pos ps += bezier([p0, p1, p2, p3])[::-1][1:] self.cpolygonkey = key self.cpolygon = thicken(ps, f * self.width) return self.cpolygon
def polygon(self, f=1): s = math.length(self.anchors[0]) CSs = [math.CS(math.radians(theta)) for theta in range(-1, 35, 3)] w = self.width * f return [((s + w) * S, (s + w) * C) for C, S in CSs] + [((s - w) * S, (s - w) * C) for C, S in reversed(CSs)]
def polygon(self, f=1): s = math.length(self.anchors[0]) w = self.width * f return [ ((s + w) * S15 - C15, (s + w) * C15 + S15), ((s + w) * S15 + C15, (s + w) * C15 - S15), ((s - w) * S15 + C15, (s - w) * C15 - S15), ((s - w) * S15 - C15, (s - w) * C15 + S15), ]
def setstate(self, x1, y1, **args): self.x1 = x1 self.y1 = y1 self.dx = self.x1 - self.x self.dy = self.y1 - self.y self.slope = self.dy / self.dx self.d = math.length((self.dx, self.dy)) self.dhat = self.dhatx, self.dhaty = math.norm((self.dx, self.dy)) self.scale = view.scale(self.z) self.d0 = self.d * self.scale
def constrain(self, pos, j): if pos[1] < 0.0001: pos = pos[0], 0.0001 if pos[0] < 0: pos = 0, pos[1] if math.dot(pos, (C30, -S30)) > 0: pos, _ = ptoline(pos, (S30, C30)) a = math.length(pos) if a > 1 - self.r: pos = math.norm(pos, 1 - self.r) return pos
def constrain(self, pos, j): if pos[1] < 0.0001: pos = pos[0], 0.0001 if pos[0] < self.width: pos = self.width, pos[1] if math.dot(math.norm(pos), (C30, -S30)) > -self.width: pos, _ = ptoline(pos, (S30, C30)) pos = pos[0] - self.width * C30, pos[1] + self.width * S30 a = math.length(pos) if a > 1 - self.width: pos = math.norm(pos, 1 - self.width) return pos
def polygon(self, f=1): s = math.length(self.pos) x, y = self.pos x0 = self.width y0 = 2 / math.tan(math.radians(30)) * self.width beta = math.atan2(x - x0, y - y0) gamma = 4 * beta - math.tau / 8 ds = beta / (math.tau / 12) s0 = (0.6 + 0.2 * ds) * s s1 = (0.8 - 0.2 * ds) * s d = 0.3 * s p0 = -0.01, s0 p1 = d, s0 C, S = math.CS(gamma + 3 / 8 * math.tau, d) p2 = x + S, y + C p3 = self.pos ps = bezier([p0, p1, p2, p3]) p0 = self.pos p1 = x + C, y - S p2 = s1 * S30 - d * C30, s1 * C30 + d * S30 p3 = s1 * S30, s1 * C30 ps += bezier([p0, p1, p2, p3])[1:] return thicken(ps, f * self.width)
def contains(self, pos): s = math.length(self.anchors[0]) d = math.length(pos) return abs(s - d) < self.width
def contains(self, pos): return math.length(view.FconvertB(self.Fspot, pos)) < 1
try: import a except ImportError: print("Error:", sys.exc_info()[0]) try: print(x) except NameError: print("Error:", sys.exc_info()[0]) try: lst = [2, 25, 41] print(lst[4]) except IndexError: print("Error:", sys.exc_info()[0]) try: import math print(math.length()) except AttributeError: print("Error:", sys.exc_info()[0]) finally: print("Try and except is finished") print('\n') #Simple calculator try: m = input("Enter the two operand:") n = input() a = float(m) b = float(n) except ValueError: print("Error:", sys.exc_info()[0]) print("+ - * /")