예제 #1
0
 def intersection_position(self, ray: Ray) -> Optional[np.ndarray]:
     pc = ray.position - self.center
     a = 1
     b = 2*np.dot(pc, ray.direction)
     c = np.dot(pc, pc) - self.radius**2
     t1, t2 = np.roots([a, b, c])
     min_t = min(t1, t2)
     t = min_t if min_t >= 10**-10 else max(t1, t2)
     return ray.point(t) if super().valid_t(t) else None
예제 #2
0
 def intersection_position(self, ray: Ray) -> Optional[np.ndarray]:
     md = self.m.dot(ray.direction)
     mpc = self.m.dot(ray.position - self.center)
     a = md.dot(md)
     b = 2*md.dot(mpc)
     c = mpc.dot(mpc) - self.semi_axes.prod()**2
     t1, t2 = np.roots([a, b, c])
     min_t = min(t1, t2)
     t = min_t if min_t >= 10**-10 else max(t1, t2)
     return ray.point(t) if super().valid_t(t) else None
예제 #3
0
def _draw_ray(ax: Axes3D,
              ray: Ray,
              length: float,
              color: str = "blue",
              line_style: str = "-",
              label: str = None):
    end_point = ray.point(length)
    x = np.array([ray.position[0], end_point[0]])
    y = np.array([ray.position[1], end_point[1]])
    z = np.array([ray.position[2], end_point[2]])
    ax.plot(x, y, z, color=color, linestyle=line_style, label=label)
def _ray_coords(ray: Ray, length: float = 5) -> Tuple[list, list]:
    end_point = ray.point(length)
    return [ray.position[0], end_point[0]], [ray.position[1], end_point[1]]
예제 #5
0
 def intersection_position(self, ray: Ray) -> Optional[np.ndarray]:
     t = np.dot(self.n, self.position - ray.position) / \
         np.dot(self.n, ray.direction)
     return ray.point(t) if super().valid_t(t) else None