def __init__(self, ps, color=None): Shape.__init__(self, color) self.vs = ps self.bound = AABox.from_vectors(*self.vs) self.half_planes = [] for i in xrange(len(self.vs)): h = HalfPlane(self.vs[i], self.vs[(i+1) % len(self.vs)]) self.half_planes.append(h)
def __init__(self, a=1.0, b=1.0, c=0.0, d=0.0, e=0.0, f=-1.0, color=None): Shape.__init__(self, color) if c*c - 4*a*b >= 0: raise Exception("Not an ellipse") self.a = a self.b = b self.c = c self.d = d self.e = e self.f = f self.gradient = Transform(2*a, c, d, c, 2*b, e) self.center = self.gradient.inverse() * Vector(0, 0) y1, y2 = quadratic(b-c*c/4*a, e-c*d/2*a, f-d*d/4*a) x1, x2 = quadratic(a-c*c/4*b, d-c*e/2*b, f-e*e/4*b) self.bound = AABox.from_vectors(Vector(-(d + c*y1)/2*a, y1), Vector(-(d + c*y2)/2*a, y2), Vector(x1, -(e + c*x1)/2*b), Vector(x2, -(e + c*x2)/2*b)) if not self.contains(self.center): raise Exception("Internal error, center not inside ellipse")
def __init__(self, a=1.0, b=1.0, c=0.0, d=0.0, e=0.0, f=-1.0, color=None): Shape.__init__(self, color) if c * c - 4 * a * b >= 0: raise Exception("Not an ellipse") self.a = a self.b = b self.c = c self.d = d self.e = e self.f = f self.gradient = Transform(2 * a, c, d, c, 2 * b, e) self.center = self.gradient.inverse() * Vector(0, 0) y1, y2 = quadratic(b - c * c / 4 * a, e - c * d / 2 * a, f - d * d / 4 * a) x1, x2 = quadratic(a - c * c / 4 * b, d - c * e / 2 * b, f - e * e / 4 * b) self.bound = AABox.from_vectors(Vector(-(d + c * y1) / 2 * a, y1), Vector(-(d + c * y2) / 2 * a, y2), Vector(x1, -(e + c * x1) / 2 * b), Vector(x2, -(e + c * x2) / 2 * b)) if not self.contains(self.center): raise Exception("Internal error, center not inside ellipse")