Beispiel #1
0
def step_impl(context):
    context.xs = intersections(
        intersection(-0.9899, context.A),
        intersection(-0.4899, context.B),
        intersection(0.4899, context.B),
        intersection(0.9899, context.A),
    )
Beispiel #2
0
    def local_intersect(self, cylinder, ray):
        a = ray.direction.x ** 2 + ray.direction.z ** 2

        xs = []
        if abs(a) > EPSILON:
            b = 2 * ray.origin.x * ray.direction.x + 2 * ray.origin.z * ray.direction.z
            c = ray.origin.x ** 2 + ray.origin.z ** 2 - 1

            discriminant = b ** 2 - 4 * a * c

            if discriminant < 0:
                return []

            t0 = (-b - sqrt(discriminant)) / (2 * a)
            t1 = (-b + sqrt(discriminant)) / (2 * a)
            t = [t0, t1]
            t = sorted(t)
            assert t[0] <= t[1]

            y0 = ray.origin.y + t0 * ray.direction.y
            if cylinder.minimum < y0 and y0 < cylinder.maximum:
                xs.append(intersection(t0, cylinder))

            y1 = ray.origin.y + t1 * ray.direction.y
            if cylinder.minimum < y1 and y1 < cylinder.maximum:
                xs.append(intersection(t1, cylinder))

        xs = self.intersect_caps(cylinder, ray, xs)

        return xs
Beispiel #3
0
    def intersect_caps(self, cylinder, ray, xs):
        if cylinder.closed is not True or abs(ray.direction.y) < EPSILON:
            return xs

        t = (cylinder.minimum - ray.origin.y) / ray.direction.y
        if self.check_cap(ray, t):
            xs.append(intersection(t, cylinder))

        t = (cylinder.maximum - ray.origin.y) / ray.direction.y
        if self.check_cap(ray, t):
            xs.append(intersection(t, cylinder))

        return xs
Beispiel #4
0
    def local_intersect(self, cube, ray):

        xtmin, xtmax = self.check_axis(ray.origin.x, ray.direction.x)
        ytmin, ytmax = self.check_axis(ray.origin.y, ray.direction.y)
        ztmin, ztmax = self.check_axis(ray.origin.z, ray.direction.z)

        tmin = max(xtmin, ytmin, ztmin)
        tmax = min(xtmax, ytmax, ztmax)

        if tmin > tmax:
            return []

        return [intersection(tmin, cube), intersection(tmax, cube)]
Beispiel #5
0
    def intersect_caps(self, cone, ray, xs):
        if cone.closed is not True or abs(ray.direction.y) <= EPSILON:
            return xs

        t = (cone.minimum - ray.origin.y) / ray.direction.y
        if self.check_cap(ray, t, cone.minimum):
            xs.append(intersection(t, cone))

        t = (cone.maximum - ray.origin.y) / ray.direction.y
        if self.check_cap(ray, t, cone.maximum):
            xs.append(intersection(t, cone))

        return xs
Beispiel #6
0
def step_impl(context):
    context.xs = intersections(
        intersection(2, context.A),
        intersection(2.75, context.B),
        intersection(3.25, context.C),
        intersection(4.75, context.B),
        intersection(5.25, context.C),
        intersection(6, context.A),
    )
Beispiel #7
0
    def local_intersect(self, cone, ray):
        a = ray.direction.x**2 - ray.direction.y**2 + ray.direction.z**2
        b = (2 * ray.origin.x * ray.direction.x -
             2 * ray.origin.y * ray.direction.y +
             2 * ray.origin.z * ray.direction.z)
        c = ray.origin.x**2 - ray.origin.y**2 + ray.origin.z**2

        xs = []
        if abs(a) < EPSILON and abs(b) < EPSILON:
            return []
        elif abs(a) < EPSILON:
            t = -c / (2 * b)
            xs.append(intersection(t, cone))
        else:
            discriminant = b**2 - 4 * a * c

            if discriminant < 0:
                return []

            t0 = (-b - sqrt(discriminant)) / (2 * a)
            t1 = (-b + sqrt(discriminant)) / (2 * a)
            t = [t0, t1]
            t = sorted(t)
            assert t[0] <= t[1]

            y0 = ray.origin.y + t0 * ray.direction.y
            if cone.minimum < y0 and y0 < cone.maximum:
                xs.append(intersection(t0, cone))

            y1 = ray.origin.y + t1 * ray.direction.y
            if cone.minimum < y1 and y1 < cone.maximum:
                xs.append(intersection(t1, cone))

        self.intersect_caps(cone, ray, xs)

        return xs
Beispiel #8
0
 def local_intersect(self, triangle, ray):
     dir_cross_e2 = cross(ray.direction, triangle.e2)
     det = dot(triangle.e1, dir_cross_e2)
     if abs(det) < EPSILON:
         return []
     else:
         f = 1.0 / det
         p1_to_origin = ray.origin - triangle.p1
         u = f * dot(p1_to_origin, dir_cross_e2)
         if u < 0 or u > 1:
             return []
         origin_cross_e1 = cross(p1_to_origin, triangle.e1)
         v = f * dot(ray.direction, origin_cross_e1)
         if v < 0 or (u + v) > 1:
             return []
         t = f * dot(triangle.e2, origin_cross_e1)
         return [intersection(t, triangle)]
Beispiel #9
0
def step_impl(context):
    context.xs = intersections(intersection(-1, context.shape),
                               intersection(1, context.shape))
Beispiel #10
0
def step_impl(context):
    context.i4 = intersection(2, context.s)
Beispiel #11
0
def step_impl(context):
    context.i3 = intersection(-3, context.s)
Beispiel #12
0
def step_impl(context):
    context.i2 = intersection(7, context.s)
Beispiel #13
0
def step_impl(context):
    context.i1 = intersection(5, context.s)
Beispiel #14
0
def step_impl(context):
    context.xs = intersections(
        intersection(-sqrt(2) / 2, context.shape),
        intersection(sqrt(2) / 2, context.shape),
    )
Beispiel #15
0
def step_impl(context):
    context.i = intersection(1, context.shape)
Beispiel #16
0
def step_impl(context):
    context.xs = intersections(intersection(1.8589, context.shape))
Beispiel #17
0
def step_impl(context):
    context.xs = intersections(intersection(sqrt(2), context.floor2))
Beispiel #18
0
def step_impl(context):
    context.i = intersection(sqrt(2), context.shape)
Beispiel #19
0
def step_impl(context):
    context.i = intersection(3.5, context.s)
Beispiel #20
0
 def local_intersect(self, s, local_ray):
     if abs(local_ray.direction.y) < EPSILON:
         return []
     else:
         t = -local_ray.origin.y / local_ray.direction.y
         return [intersection(t, s)]
Beispiel #21
0
def step_impl(context):
    context.i = intersection(4, context.s2)