示例#1
0
def find_intersections(Cs, Qs, plucker, ray_ind, planes, sel):
    '''
    Plucker coords make the collision check quite fast, requiring few ops.

    Cs, Qs, plucker: Canonical and Plucker representations of set of rays
    ray_ind: Specific inds of the rays/ray triangle that's being intersected
    plane: Plane describing the ray triangle
    sel: Subset of rays to check
    '''
    N = Cs.shape[0]

    pl1a, pl1b = plucker[ray_ind], plucker[ray_ind + 1]
    plane = planes[ray_ind]

    intersects = empty(N, np.int64)
    ps1 = empty((N, 3), Cs.dtype)
    us = empty((N, 3), Cs.dtype)
    j = 0

    pl2a = plucker.T[:, sel]
    pl2b = plucker.T[:, sel + 1]
    skews = np.sign( Geom.check_plucker(pl1a, pl2a) ) \
            + np.sign( Geom.check_plucker(pl1a, pl2b) ) \
            + np.sign( Geom.check_plucker(pl1b, pl2a) ) \
            + np.sign( Geom.check_plucker(pl1b, pl2b) )

    for s, i in enumerate(sel):
        if abs(skews[s]) == 4:
            # Both rays skew on the same side of the other 2 rays
            continue

        # Find the intersection of the rays with the plane
        c1, c2 = Cs[i], Cs[i + 1]
        q1, q2 = Qs[i], Qs[i + 1]
        t1, int1 = Geom.intersect_line_plane(c1, q1, plane)
        t2, int2 = Geom.intersect_line_plane(c2, q2, plane)
        if not int1 or not int2:
            continue

        intersects[j] = i
        for k in range(3):
            ps1[j, k] = c1[k] + t1 * q1[k]
            us[j, k] = (c2[k] + t2 * q2[k]) - ps1[j, k]
            # ps2[j, k] = c2[k] + t2*q2[k]
        j += 1

    return ps1[:j], us[:j], intersects[:j]
示例#2
0
def find_intersections(Cs, Qs, plucker, ray_ind, plane, sel):
    '''
    Cs, Qs, plucker: Canonical and Plucker representations of set of rays
    ray_ind: Specific inds of the rays/ray triangle that's being intersected
    plane: Plane describing the ray triangle
    sel: Subset of rays to check
    '''
    N = Cs.shape[0]

    pl1 = plucker[ray_ind:ray_ind + 2]

    intersects = empty(N, np.int64)
    ps = empty((N, 3), Cs.dtype)
    us = empty((N, 3), Cs.dtype)
    j = 0

    for k, i in enumerate(sel):
        pl2 = plucker[i:i + 2]
        skew = empty(4, np.int16)
        for a in range(2):
            for b in range(2):
                skew[2 * a + b] = np.sign(Geom.check_plucker(pl1[a], pl2[b]))
        if abs(skew.sum()) == 4:
            # Both rays skew on the same side of the other 2 rays
            continue

        # Find the intersection of the rays with the plane
        c1, c2 = Cs[i], Cs[i + 1]
        q1, q2 = Qs[i], Qs[i + 1]
        t1, int1 = Geom.intersect_line_plane(c1, q1, plane)
        t2, int2 = Geom.intersect_line_plane(c2, q2, plane)
        if not int1 or not int2:
            continue

        intersects[j] = k
        ps[j] = c1 + t1 * q1
        us[j] = (c2 + t2 * q2) - ps[j]
        j += 1

    return ps[:j], us[:j], intersects[:j]