示例#1
0
def add(u: Vector = ZEROS, v: Vector = ZEROS) -> Vertices:
    u, v = make_compatible(u, v)
    max_len = max(u.shape[0], v.shape[0])
    out = np.zeros((max_len, 4))
    out[:, :3] = u[:, :3] + v[:, :3]
    out[:, 3] = max(u[0, 3], v[0, 3])
    return out
示例#2
0
def distance(u: Vector = ZEROS, v: Vector = ZEROS) -> Float:
    # speed!?  http://stackoverflow.com/a/9184560/1243487
    # return length(sub(u, v))

    u, v = make_compatible(u, v)
    x = u[:, :3] - v[:, :3]
    return np.sqrt((x * x).sum(axis=1))
示例#3
0
def sub(u: Vector = ZEROS, v: Vector = ZEROS) -> Vertices:
    # return add(u, opposite(v))
    u, v = make_compatible(u, v)
    max_len = max(u.shape[0], v.shape[0])
    out = np.zeros((max_len, 4))
    out[:, :3] = u[:, :3] - v[:, :3]
    out[:, 3] = max(u[0, 3], v[0, 3])
    return out
示例#4
0
def merge(a: Vertices = None,
          b: Vertices = None,
          mix: BoolP(description="interleave") = False) -> Vertices:
    if a is None:
        return b
    if b is None:
        return a
    if mix:
        a, b = make_compatible(a, b, broadcast=False)
        new_l = len(a) + len(b)
        out = np.empty((new_l, 4))
        out[::2] = a
        out[1::2] = b
        return out
    else:
        return np.concatenate((a, b))
示例#5
0
def dot(u: Vector = ZEROS, v: Vector = ZEROS) -> Float:
    u, v = make_compatible(u, v)
    return np.sum(u[:, :3] * v[:, :3], axis=1)  # .. not sure
示例#6
0
def scale(u: Vector = ZEROS, s: Float = 1.0) -> Vertices:
    u, s = make_compatible(u, s[:, np.newaxis])
    out = u.copy()
    out[:, :3] = u[:, :3] * s[:, :3]
    return out
示例#7
0
def cross(u: Vector = X_AXIS, v: Vector = Y_AXIS) -> Vertices:
    u, v = make_compatible(u, v)
    max_len = max(u.shape[0], v.shape[0])
    out = np.zeros((max_len, 4))
    out[:, :3] = np.cross(u[:, :3], v[:, :3])
    return out
示例#8
0
def component_mul(u: Vector = ONES, v: Vector = ONES) -> Vertices:
    u, v = make_compatible(u, v)
    return u * v