Vector Unitze

''' ---------------
''' Unitize a 3D vector
''' ---------------
Function VectorUnitize(v)

VectorUnitize = Null
Dim dist, x, y, z, x2, y2, z2

x = v(XX) : y = v(YY) : z = v(ZZ)
x2 = x * x : y2 = y * y : z2 = z * z

dist = x2 + y2 + z2
If dist <= 0.0 Then Exit Function
dist = Sqr(dist)

x = x / dist
y = y / dist
z = z / dist

VectorUnitize = Array(x, y, z)
End Function

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License