2009年1月12日星期一

function | sort surface size by bounding box

input:

breps or srfs, amount>=2

output:

(0)   sorted srfs ID

(1)  sorted size dimension - SortSrfBySize(1)(0) is the biggest srf diaganal size

(2)  the array of the center points


snap0425

 

Function SortSrfBySize (ByVal objs)
    Dim n:n=ubound(objs)
    Dim i,j,k,boxLong(),objtemp,boxcenter(),temp(2)
    For i=0 To n-1
        For j=0 To n-1
            ReDim Preserve boxLong(j)
            boxLong(j)=rhino.distance(rhino.BoundingBox(objs(j))(0),rhino.BoundingBox(objs(j))(6))
            ReDim Preserve boxLong(j+1)
            boxLong(j+1)=rhino.distance(rhino.BoundingBox(objs(j+1))(0),rhino.BoundingBox(objs(j+1))(6))
            If boxLong(j)<boxLong(j+1) Then
                objtemp=objs(j)
                objs(j)=objs(j+1)
                objs(j+1)=objtemp
            End If       
        Next       
    Next
    For k=0 To n       
        ReDim Preserve boxcenter(k)   
        ReDim Preserve boxLong(k)
        boxcenter(k)=rhino.Pointscale(rhino.PointAdd(rhino.BoundingBox(objs(k))(0),rhino.BoundingBox(objs(K))(6)),0.5)
        boxLong(k)=rhino.distance(rhino.BoundingBox(objs(k))(0),rhino.BoundingBox(objs(k))(6))
    Next
    temp(0)=objs
    temp(1)=boxLong
    temp(2)=boxcenter
    SortSrfBySize=temp
    'SortSrfBySize(0) are the sorted srfs ID
    'SortSrfBySize(1) are the sorted size dimension - SortSrfBySize(1)(0) is the biggest srf diaganal size
    'SortSrfBySize(2) are the array of the center points
End Function

没有评论:

发表评论