Example #1
0
 def bound(self, state):
     c, r, a = self.center_radius_angle(state.m)
     # Use derivative of ellipse equation to find angle of min max points
     tx = dmath.atan2(-r[1] * dmath.sin(a[0]), -r[0] * dmath.cos(a[0]))
     ty = dmath.atan2(r[1] * dmath.cos(a[0]), -r[0] * dmath.sin(a[0]))
     # plug those numbers back into the ellipse equations
     dx = dmath.fabs(r[0] * dmath.cos(tx) * dmath.cos(a[0]) - r[1] * dmath.sin(tx) * dmath.sin(a[0]))
     dy = dmath.fabs(r[0] * dmath.cos(ty) * dmath.sin(a[0]) + r[1] * dmath.sin(ty) * dmath.cos(a[0]))
     return ((c[0] - dx, c[1] - dy), (c[0] + dx, c[1] + dy))
Example #2
0
 def __init__(self, argument):
     from cas.numeric import Integer
     Function.__init__(self,
                       'sin',
                       argument,
                       action=lambda x: dmath.sin(x)
                       if isinstance(x,
                                     (Decimal, Integer)) else math.sin(x))
Example #3
0
 def __init__(self, r, sweep=None):
     super(circle, self).__init__()
     r = D(r)
     self.points.append((D(0), D(0)))
     self.points.append((r, D(0)))
     self.points.append((D(0), r))
     if sweep is not None:
         assert sweep > 0 and sweep < 360
         sweep = dmath.radians(D(sweep))
         self.points.append((dmath.cos(sweep) * r, dmath.sin(sweep) * r))
     self.full = sweep is None
Example #4
0
    def rect_pad(self, name, points, rounded, state):
        m = []
        ret = []
        for i in range(len(points)):
            p0, p1 = points[i], points[(i + 1) % len(points)]
            m.append(((p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2))
        dim0 = dmath.hypot(m[2][0] - m[0][0], m[2][1] - m[0][1])
        dim1 = dmath.hypot(m[3][0] - m[1][0], m[3][1] - m[1][1])

        c = ((m[0][0] + m[2][0]) / 2, (m[0][1] + m[2][1]) / 2)

        if dim0.quantize(D("0.000001")) == dim1.quantize(D("0.000001")):
            if rounded:
                ret.append(circ_pad(name, c, dim0 / 2), state)
            else:
                ret += self.rect_pad(name, [ points[0], points[1], m[1], m[3] ], False, state)
                ret += self.rect_pad(name, [ m[3], m[1], points[2], points[3] ], False, state)
            return ret
        if dim0 > dim1:
            angle = dmath.atan2(m[2][1] - m[0][1], m[2][0] - m[0][0])
        else:
            angle = dmath.atan2(m[3][1] - m[1][1], m[3][0] - m[1][0])

        flags = []
        if not rounded:
            flags.append("square")
        if state.get_onsolder():
            flags.append("onsolder")
        if not state.get_paste():
            flags.append("nopaste")

        thickness = min(dim0, dim1) / 2
        width = max(dim0, dim1) - thickness * 2
        p = []
        p.append((c[0] + dmath.cos(angle) * width / 2, c[1] + dmath.sin(angle) * width / 2))
        p.append((c[0] - dmath.cos(angle) * width / 2, c[1] - dmath.sin(angle) * width / 2))
        ret.append("""Pad [ %s %s %s %s %s %s %s "%s" "%s" "%s" ]""" % (
            P(p[0][0]), P(p[0][1]), P(p[1][0]), P(p[1][1]), P(thickness * 2),
            P(self.clearance * 2), P((self.mask + thickness) * 2), name, name,
            ",".join(flags)))
        return ret
Example #5
0
    h = D2 * a / d
    dr = Vec(x1 - x0, y1 - y0)
    dx = vscale(sqrt(r0 ** 2 - h ** 2), vnorm(dr))
    ang = vangle(dr) if \
          r0 ** 2 + d ** 2 > r1 ** 2 \
          else pi + vangle(dr)
    da = asin(h / r0)
    return map(anorm, [ang - da, ang + da])

# Angles of the start and end points of the circle arc.
Angle2 = namedtuple("Angle2", "a1 a2")

Arc = namedtuple("Arc", "c aa")

arcPoint = lambda (x, y, r), a: \
    vadd(Vec(x, y), Vec(r * cos(a), r * sin(a)))

arc_start  = lambda (c, (a0, a1)):  arcPoint(c, a0)
arc_mid    = lambda (c, (a0, a1)):  arcPoint(c, (a0 + a1) / D2)
arc_end    = lambda (c, (a0, a1)):  arcPoint(c, a1)
arc_center = lambda ((x, y, r), _): Vec(x, y)

arc_area = lambda ((_0, _1, r), (a0, a1)):  r ** 2 * (a1 - a0) / D2

def split_circles(cs):
    cSplit = lambda (c, angs): \
        imap(Arc, repeat(c), imap(Angle2, angs, angs[1:]))

    # If an arc that was part of one circle is inside *another* circle,
    # it will not be part of the zero-winding path, so reject it.
    in_circle = lambda ((x0, y0), c), (x, y, r): \
Example #6
0
def test_sin():

    for x in range(-10, 10):
        assert dmath.sin(x) == math.sin(x)
        assert grad(dmath.sin)(x) == math.cos(x)
Example #7
0
 def f_prime(x, y):
     return (cos(x) * cos(y), -sin(x) * sin(y))
Example #8
0
 def f(x, y):
     return sin(x) * cos(y)
Example #9
0
 def g(x):
     return sin(x**2)
Example #10
0
 def __init__(self, a):
     super(rotate, self).__init__()
     a = dmath.radians(D(a))
     self.m[0,0] = self.m[1,1] = D(dmath.cos(a))
     self.m[0,1] = D(dmath.sin(a))
     self.m[1,0] = -D(dmath.sin(a))
 def __init__(self, argument):
     from cas.numeric import Integer
     Function.__init__(self, 'sin', argument, action=lambda x: dmath.sin(x)
         if isinstance(x, (Decimal, Integer)) else math.sin(x))