def intersect_caps(self, local_ray): xs = [] if self.closed == True and not equal(local_ray.direction.y, 0): # check for an intersection with the lower end cap by intersecting the ray with the plane at y=cyl.minimum t = (self.minimum - local_ray.origin.y) / local_ray.direction.y if self.check_cap(local_ray, t): xs.append(Intersection(t, self)) # check for an intersection with the upper end cap by intersecting the ray with the plane at y=cyl.maximum t = (self.maximum - local_ray.origin.y) / local_ray.direction.y if self.check_cap(local_ray, t): xs.append(Intersection(t, self)) return xs
def local_intersect(self, local_ray): xtmin, xtmax = self.check_axis(local_ray.origin.x, local_ray.direction.x) ytmin, ytmax = self.check_axis(local_ray.origin.y, local_ray.direction.y) ztmin, ztmax = self.check_axis(local_ray.origin.z, local_ray.direction.z) tmin = max(xtmin, ytmin, ztmin) tmax = min(xtmax, ytmax, ztmax) if tmin > tmax: return [] return [Intersection(tmin, self), Intersection(tmax, self)]
def local_intersect(self, local_ray): sphere_to_ray = local_ray.origin - self.origin a2 = 2 * dot(local_ray.direction, local_ray.direction) b = 2 * dot(local_ray.direction, sphere_to_ray) c = dot(sphere_to_ray, sphere_to_ray) - 1 discriminant = (b * b) - (2 * a2 * c) if discriminant < 0: return () else: scale_value = 1.0 / a2 v = scale_value * np.sqrt(discriminant) w = scale_value * b t1 = np.float32(-(v + w)) t2 = np.float32(v - w) return (Intersection(t1, self), Intersection(t2, self))
def local_intersect(self, local_ray): xs = [] [dx, dy, dz, dw] = local_ray.direction [ox, oy, oz, ow] = local_ray.origin a = (dx * dx) + (dz * dz) - (dy * dy) b = 2 * ((ox * dx) + (oz * dz) - (oy * dy)) c = ((ox * ox) + (oz * oz) - (oy * oy)) if math.fabs(a) > (EPSILON): # a is not zero e2 = (EPSILON / 2) if self.closed else 0 disc = (b * b) - (4 * a * c) if (disc + EPSILON) >= 0: if disc < 0: disc = 0 ds = np.float32(math.sqrt(disc)) scale_factor = np.float32(1.0 / (2 * a)) t0 = -scale_factor * (ds + b) t1 = scale_factor * (ds - b) if t0 > t1: temp = t0 t0 = t1 t1 = temp y0 = local_ray.origin.y + (t0 * local_ray.direction.y) if (self.minimum - e2) < y0 and y0 < (self.maximum + e2): xs.append(Intersection(np.float32(t0), self)) y1 = local_ray.origin.y + (t1 * local_ray.direction.y) if (self.minimum - e2) < y1 and y1 < (self.maximum + e2): xs.append(Intersection(np.float32(t1), self)) else: # a is approximately zero if math.fabs(b) > EPSILON: # b is non-zero t = np.float32(-c / (2 * b)) xs.append(Intersection(t, self)) if self.closed: cap_intersects = self.intersect_caps(local_ray) for item in cap_intersects: xs.append(item) return xs
def local_intersect(self, local_ray): xs = [] dx = local_ray.direction.x dz = local_ray.direction.z a = (dx * dx) + (dz * dz) if a > (EPSILON): e2 = (EPSILON / 2) if self.closed else 0 #print("--ray not parallel to Y axis") rx = local_ray.origin.x rz = local_ray.origin.z b = np.float32(2 * ((rx * dx) + (rz * dz))) c = np.float32((rx * rx) + (rz * rz) - 1) disc = (b * b) - (4 * a * c) if disc >= 0: #print("-- ray may intersect wall of cylinder") ds = np.float32(math.sqrt(disc)) scale_factor = np.float32(1.0 / (2 * a)) t0 = -scale_factor * (ds + b) t1 = scale_factor * (ds - b) if t0 > t1: temp = t0 t0 = t1 t1 = temp y0 = local_ray.origin.y + (t0 * local_ray.direction.y) #print("self.min, y0, self.max, y0: ", self.minimum, y0, self.maximum) if (self.minimum - e2) < y0 and y0 < (self.maximum + e2): xs.append(Intersection(np.float32(t0), self)) #print("-- ray intersects wall of cylinder") y1 = local_ray.origin.y + (t1 * local_ray.direction.y) #print("self.min, y1, self.max, y1: ", self.minimum, y1, self.maximum) if (self.minimum - e2) < y1 and y1 < (self.maximum + e2): xs.append(Intersection(np.float32(t1), self)) #print("-- ray intersects wall of cylinder") #else: #print("-- ray will NOT intersect wall of cylinder") #else: #print("-- ray IS parallel to Y axis") cap_intersects = self.intersect_caps(local_ray) for item in cap_intersects: xs.append(item) return xs
def local_intersect(self, local_ray): if abs(local_ray.direction.y) < EPSILON: return () t = np.float32(-local_ray.origin.y / local_ray.direction.y) return ([Intersection(t, self)])