示例#1
0
def Intersect_Grid_Square(gpos, xxx_todo_changeme5):
    (a, b) = xxx_todo_changeme5
    (x, y) = gpos
    x -= 0.5
    y -= 0.5
    for (c, d) in [((x, y), (x + 1, y + 1)), ((x + 1, y), (x, y + 1))]:
        if (intersect.Intersect((a, b), (c, d)) != None):
            return True

    return False
示例#2
0
    def ray_intersect(self, orig, direction):
        try:
            invdir = V3(1 / direction.x, 1 / direction.y, 1 / direction.z)
        except:
            return None
        if invdir.x >= 0:
            tmin = (self.x - orig.x) * invdir.x
            tmax = (self.x2 - orig.x) * invdir.x
        else:
            tmin = (self.x2 - orig.x) * invdir.x
            tmax = (self.x - orig.x) * invdir.x
        if invdir.y >= 0:
            tymin = (self.y - orig.y) * invdir.y
            tymax = (self.y2 - orig.y) * invdir.y
        else:
            tymin = (self.y2 - orig.y) * invdir.y
            tymax = (self.y - orig.y) * invdir.y

        if ((tmin > tymax) or (tymin > tmax)):
            return None
        if (tymin > tmin):
            tmin = tymin
        if (tymax < tmax):
            tmax = tymax

        if invdir.z >= 0:
            tzmin = (self.z - orig.z) * invdir.z
            tzmax = (self.z2 - orig.z) * invdir.z
        else:
            tzmin = (self.z2 - orig.z) * invdir.z
            tzmax = (self.z - orig.z) * invdir.z

        if (tmin > tzmax) or (tzmin > tmax):
            return None
        if (tzmin > tmin):
            tmin = tzmin
        if (tzmax < tmax):
            tmax = tzmax

        t = tmin

        if t < 0:
            t = tmax
        if t < 0:
            return None

        xmid = (self.x + self.x2) / 2
        ymid = (self.y + self.y2) / 2
        zmid = (self.z + self.z2) / 2
        center = V3(xmid, ymid, zmid)
        hit = sum(orig, mul(direction, t))
        normal = norm(sub(hit, center))
        return intersect.Intersect(distance=t, point=hit, normal=normal)
示例#3
0
    def ray_intersect(self, orig, direction):
        L = sub(self.center, orig)
        tca = dot(L, direction)
        l = length(L)
        d2 = l**2 - tca**2
        if d2 > self.radius**2:
            return None
        thc = (self.radius**2 - d2)**1 / 2
        t0 = tca - thc
        t1 = tca + thc
        if t0 < 0:
            t0 = t1
        if t0 < 0:
            return None

        hit = sum(orig, mul(direction, t0))

        normal = norm(sub(hit, self.center))

        return intersect.Intersect(distance=t0, point=hit, normal=normal)