def construct_center_polygon(n: int, k: int, quasiregular: bool) -> Polygon: # Initialize P as the center polygon in an n-k regular or quasiregular tiling. # Let ABC be a triangle in a regular (n,k0-tiling, where # A is the center of an n-gon (also center of the disk), # B is a vertex of the n-gon, and # C is the midpoint of a side of the n-gon adjacent to B. angle_a = pi / n angle_b = pi / k angle_c = pi / 2 # For a regular tiling, we need to compute the distance s from A to B. sin_a = sin(angle_a) sin_b = sin(angle_b) s = sin(angle_c - angle_b - angle_a) / sqrt(Decimal(1) - sin_b * sin_b - sin_a * sin_a) # But for a quasiregular tiling, we need the distance s from A to C. if quasiregular: s = (s * s + Decimal(1)) / (Decimal(2) * s * cos(angle_a)) s = s - sqrt(s * s - Decimal(1)) # Now determine the coordinates of the n vertices of the n-gon. # They're all at distance s from the center of the Poincare disk. poly = [Point(s, s) for _ in range(n)] for i, pt in enumerate(poly): pt.x *= cos(Decimal(3 + 2 * i) * angle_a) pt.y *= sin(Decimal(3 + 2 * i) * angle_a) return poly
def p_expression_function(t): 'expression : FUNCTION LPAREN expression RPAREN' if t[1] == 'sqrt': t[0] = t[3].sqrt() elif t[1] == 'sin': t[0] = sin(t[3]) elif t[1] == 'cos': t[0] = cos(t[3]) elif t[1] == 'ln': t[0] = t[3].ln() elif t[1] == 'log': t[0] = t[3].log10() elif t[1][:4] == 'log_': try: b = Decimal(t[1][4:]) t[0] = t[3].log10() / b.log10() except decimal.InvalidOperation: print "Cannot evaluate %s%s%s%s. " \ "Setting it to 0." % (t[1], t[2], t[3], t[4]) t[0] = Decimal(0)
def _eval_power(b, e): """ b is Real but not equal to rationals, integers, 0.5, oo, -oo, nan e is symbolic object but not equal to 0, 1 (-p) ** r -> exp(r * log(-p)) -> exp(r * (log(p) + I*Pi)) -> -> p ** r * (sin(Pi*r) + cos(Pi*r) * I) """ if isinstance(e, Number): if isinstance(e, Integer): e = e.p return Real(decimal_math.pow(b.num, e)) e2 = e._as_decimal() if b.is_negative and not e.is_integer: m = decimal_math.pow(-b.num, e2) a = decimal_math.pi() * e2 s = m * decimal_math.sin(a) c = m * decimal_math.cos(a) return Real(s) + Real(c) * S.ImaginaryUnit return Real(decimal_math.pow(b.num, e2)) return
def _eval_power(b, e): if e.is_odd: return S.NegativeOne if e.is_even: return S.One if isinstance(e, Number): if isinstance(e, Real): a = e.num * decimal_math.pi() s = decimal_math.sin(a) c = decimal_math.cos(a) return Real(s) + Real(c) * S.ImaginaryUnit if isinstance(e, NaN): return S.NaN if isinstance(e, (Infinity, NegativeInfinity)): return S.NaN if isinstance(e, Half): return S.ImaginaryUnit if isinstance(e, Rational): if e.q == 2: return S.ImaginaryUnit ** Integer(e.p) q = int(e) if q: q = Integer(q) return b ** q * b ** (e - q) return
def x(self, t: Decimal) -> Decimal: return self._x + self._r * cos(t)
def cos(self): return Real(decimal_math.cos(self._as_decimal())) def tan(self): return Real(decimal_math.tan(self._as_decimal()))