def scale_matrix(factor, origin=None, direction=None):
if direction is None:<EOL><INDENT>M = numpy.diag([factor, factor, factor, <NUM_LIT:1.0>])<EOL>if origin is not None:<EOL><INDENT>M[:<NUM_LIT:3>, <NUM_LIT:3>] = origin[:<NUM_LIT:3>]<EOL>M[:<NUM_LIT:3>, <NUM_LIT:3>] *= <NUM_LIT:1.0> - factor<EOL><DEDENT><DEDENT>else:<EOL><INDENT>direction = unit_vector(direction[:<NUM_LIT:3>])<EOL>factor = <NUM_LIT:1.0> - factor<EOL>M = numpy.identity(<NUM_LIT:4>)<EOL>M[:<NUM_LIT:3>, :<NUM_LIT:3>] -= factor * numpy.outer(direction, direction)<EOL>if origin is not None:<EOL><INDENT>M[:<NUM_LIT:3>, <NUM_LIT:3>] = (factor * numpy.dot(origin[:<NUM_LIT:3>], direction)) * direction<EOL><DEDENT><DEDENT>return M<EOL>
Return matrix to scale by factor around origin in direction.

    Use factor -1 for point symmetry.

    >>> v = (numpy.random.rand(4, 5) - 0.5) * 20
    >>> v[3] = 1
    >>> S = scale_matrix(-1.234)
    >>> numpy.allclose(numpy.dot(S, v)[:3], -1.234*v[:3])
    True
    >>> factor = random.random() * 10 - 5
    >>> origin = numpy.random.random(3) - 0.5
    >>> direct = numpy.random.random(3) - 0.5
    >>> S = scale_matrix(factor, origin)
    >>> S = scale_matrix(factor, origin, direct)