Function VectorProjectedLength(arrSrc, arrDest)
'' Returns the length of the vector which results from the projection of the source vector onto the destination vector
VectorProjectedLength = Rhino.VectorDotProduct(arrSrc,Rhino.VectorUnitize(arrDest))
End Function
Function VectorProject(arrSrc, arrDest)
''Returns the vector which results from the projection of the source vector onto the destination vector
VectorProject = VectorResize(arrDest,VectorProjectedLength(arrSrc, arrDest))
End Function
Function VectorResize(arrVec, dblSize)
Dim v : v = Rhino.VectorUnitize(arrVec)
VectorResize = Rhino.VectorScale(v,dblSize)
End Function
Function Centroid(arrPts)
Dim cent, n
cent = array(0,0,0)
For n=0 To Ubound(arrPts)
cent = Rhino.VectorAdd(cent, arrPts(n))
Next
cent = Rhino.VectorScale(cent, 1/(Ubound(arrPts)+1))
Centroid = cent
End Function
Function PointInterpolate(arrPtA, arrPtB, t)
Dim vec
vec = Rhino.VectorCreate(arrPtB, arrPtA)
vec = Rhino.VectorScale(vec,t)
PointInterpolate = Rhino.PointAdd(arrPtA, vec)
End Function
Function ScalePtsAboutCentroid(arrPts, scale)
Dim cent, tVec
cent = Centroid(arrPts)
tVec = Rhino.VectorCreate(array(0,0,0), cent)
Dim n
For n=0 To Ubound(arrPts)
arrPts(n) = Rhino.PointAdd(arrPts(n), tVec)
arrPts(n) = Rhino.PointScale(arrPts(n), scale)
arrPts(n) = Rhino.PointAdd(arrPts(n), Rhino.VectorReverse(tVec))
Next
ScalePtsAboutCentroid = arrPts
End Function
Function VectorCompare(arrVecA, arrVecB)
'' compares two vectors, see if they are pointing basically the same way
VectorCompare = False
If (VectorProjectedLength(arrVecA, arrVecB) > 0 ) Then VectorCompare = True
End Function
Function DistanceXY(arrPtA, arrPtB)
DistanceXY = ( (arrPtA(0)-arrPtB(0))^2 + (arrPtA(1)-arrPtB(1))^2 )^0.5
End Function
Tags:
Rhinoscript,
sample script,
utility,
vector,
vector math