示例#1
0
    def intersect(self, ray):
        r = ray.direction

        if r.z * self.R <= 0:  # backlit
            return None

        a = ray.endpoint + Vec(0, 0, self.R)
        b = a + r

        t = quadratic((b.z - a.z) ** 2 + (b.y - a.y) ** 2,
                      2 * a.z * (b.z - a.z) + 2 * a.y * (b.y - a.y),
                      a.z ** 2 + a.y ** 2 - self.R ** 2)

        if t is None or t < 0:  # no intersection
            return None
        else:
            if self.R > 0:
                if a.z + max(t) * r.z > 0:
                    p = a + max(t) * r
                else:
                    p = a + min(t) * r
            else:
                if a.z + min(t) * r.z < 0:
                    p = a + min(t) * r
                else:
                    p = a + max(t) * r
            if (self.xsize is None and self.ysize is None) or (
                    -self.xsize / 2 <= p.x <= self.xsize / 2 and
                    -self.ysize / 2 <= p.y <= self.ysize / 2):
                return Vec(p.x, p.y, p.z - self.R)
            else:
                return None
示例#2
0
    def intersect(self, ray):
        a, b, c = self.a, self.b, self.c
        r = ray.direction
        p0 = ray.endpoint + Vec(0, 0, c)

        t = quadratic(
            r.z ** 2 + c ** 2 * r.x ** 2 / a ** 2 +
                c ** 2 * r.y ** 2 / b ** 2,
            2 * p0.z * r.z + c ** 2 * 2 * p0.x * r.x /
                a ** 2 + c ** 2 * 2 * p0.y * r.y / b ** 2,
            p0.z ** 2 + c ** 2 * p0.x ** 2 / a ** 2 + c ** 2 * p0.y ** 2 /
                b ** 2 - c ** 2)

        if t is None:  # no intersection
            return None
        else:
            # Figure out which intersection we should use
            if self.a * self.b * self.c > 0:
                if p0.z + max(t) * r.z > 0:
                    p = p0 + max(t) * r
                else:
                    p = p0 + min(t) * r
            else:
                if p0.z + min(t) * r.z < 0:
                    p = p0 + min(t) * r
                else:
                    p = p0 + max(t) * r
            if (self.xsize is None and self.ysize is None) or (
                    (-self.xsize / 2 <= p.x <= self.xsize / 2) and
                    (-self.ysize / 2 <= p.y <= self.ysize / 2)):
                return Vec(p.x, p.y, p.z - c)
            else:
                return None
示例#3
0
 def intersect(self, ray):
     r = ray.direction
     p = ray.endpoint
     a2, b2, c = self.a ** 2, self.b ** 2, self.c
     xsize, ysize = self.xsize, self.ysize
     t = quadratic(r.x ** 2 / a2 + r.y ** 2 / b2,
                   2 * p.x * r.x / a2 + 2 * p.y * r.y / b2 - r.z / c,
                   p.x ** 2 / a2 + p.y ** 2 / b2 - p.z / c)
     if t is None or t < 0:  # no intersection
         return None
     else:
         if self.concave:
             ip = p + max(t) * r
         else:
             ip = p + min(t) * r
         if ((xsize is None and ysize is None)
             or (-xsize / 2 <= ip.x <= xsize / 2
                 and -ysize / 2 <= ip.y <= ysize / 2)):
             return ip
         else:
             return None
示例#4
0
    def intersect(self, ray):

        r = ray.direction
        #if r.z * self.R <= 0:  # backlit
            #print "backlit"
            #return None

        a = ray.endpoint + Vec(0, 0, self.R)

        t = quadratic(r.z ** 2 + r.x ** 2 + r.y ** 2,
                      2 * a.z * r.z + 2 * a.x * r.x + 2 * a.y * r.y,
                      a.z ** 2 + a.x ** 2 + a.y ** 2 - self.R ** 2)

        if t is None or t < 0:  # no
            # intersection
            print "missed"
            return None
        else:
            # Figure out which intersection we should use
            if self.R > 0:
                if a.z + max(t) * r.z > 0:
                    p = a + max(t) * r
                else:
                    p = a + min(t) * r
            else:
                if a.z + min(t) * r.z < 0:
                    p = a + min(t) * r
                else:
                    p = a + max(t) * r
            if (self.xsize is None and self.ysize is None) or (
                    (-self.xsize / 2 <= p.x <= self.xsize / 2) and
                    (-self.ysize / 2 <= p.y <= self.ysize / 2)):
                return Vec(p.x, p.y, p.z - self.R)
                #return Vec(p.x, p.y, p.z)
            else:
                print "outside"
                return None