Surface Align

''' rotate surfaces to align their normal to a point
''' —-

Function Surfaceorientation (arrSurfaces, point)
'calcuate vector from point to each srf
Dim srf
For Each srf In arrSurfaces
'find center of each srf
Dim arrCentroid:arrCentroid=Rhino.SurfaceAreaCentroid(srf)
'arrCentroid(0) is the center point
Dim lightVector:lightVector=Rhino.VectorCreate( point,arrCentroid(0) )

'calculate normal to srf
Dim srfNormal:srfNormal=Rhino.SurfaceNormal( srf, Array(0,0) )
'normalize vectors

'calcuate dot product and convert to radians
Dim Angle:Angle=acos(Rhino.VectorDotProduct( lightVector,srfNormal))

'calculate rotation axis
Dim rotAxis:rotAxis=Rhino.VectorCrossProduct(lightVector, srfNormal )

'rotate srf by that angle
Call Rhino.RotateObject(srf,arrCentroid(0),360-Rhino.toDegrees(angle),rotAxis)


End Function

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