#NEWLINE# def scale_matrix( factor , origin = None , direction = None ) : #NEWLINE# #INDENT# 'Return matrix to scale by factor around origin in direction.\n\n    Use factor -1 for point symmetry.\n\n    >>> v = (numpy.random.rand(4, 5) - 0.5) * 20.0\n    >>> v[3] = 1.0\n    >>> S = scale_matrix(-1.234)\n    >>> numpy.allclose(numpy.dot(S, v)[:3], -1.234*v[:3])\n    True\n    >>> factor = random.random() * 10 - 5\n    >>> origin = numpy.random.random(3) - 0.5\n    >>> direct = numpy.random.random(3) - 0.5\n    >>> S = scale_matrix(factor, origin)\n    >>> S = scale_matrix(factor, origin, direct)\n\n    ' #NEWLINE# if ( direction is None ) : #NEWLINE# #INDENT# M = numpy . array ( ( ( factor , 0.0 , 0.0 , 0.0 ) , ( 0.0 , factor , 0.0 , 0.0 ) , ( 0.0 , 0.0 , factor , 0.0 ) , ( 0.0 , 0.0 , 0.0 , 1.0 ) ) , dtype = numpy . float64 ) #NEWLINE# if ( origin is not None ) : #NEWLINE# #INDENT# M [ : 3 , 3 ] = M [ : 3 ] #NEWLINE# M [ : 3 , 3 ] *= ( 1.0 - factor ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# direction = unit_vector ( direction [ : 3 ] ) #NEWLINE# factor = ( 1.0 - factor ) #NEWLINE# M = numpy . identity ( 4 ) #NEWLINE# M [ : 3 , : 3 ] -= ( factor * numpy . outer ( direction , direction ) ) #NEWLINE# if ( origin is not None ) : #NEWLINE# #INDENT# M [ : 3 , 3 ] = ( ( factor * numpy . dot ( origin [ : 3 ] , direction ) ) * direction ) #NEWLINE# #UNINDENT# #UNINDENT# return M