rvb Surface Slope Classification

rvb animation snippet example

Sample script to classify surface slope. It calculates the angle between the normal to the surface in its center and the vertical axis [by default, Z]. It then assigns a material color to the object depending on the value obtain in the angle calculation.

Option Explicit

'Script written by Adolfo Nadal

'Script by archiologics · www.archiologics.com

Call Main()

Sub Main()

Dim arrSrf, strSrf, arrNew 

arrSrf = Rhino.GetObjects("Select surfaces", 8, vbTrue)

If IsNull(arrSrf) Then Exit Sub

If Not isarray(arrSrf)  Then Exit Sub

Call Rhino.AddLayer("slopes analysis",255,vbtrue,vbfalse)

Call Rhino.ObjectLayer(arrSrf,"slopes analysis")

Dim value1, value2, value3, value4

'we ask the user to define the intervals we are going to use to classificate the surfaces

Call Rhino.print ("we are going to classificate the surfaces in 5 cases depending on the slope") 

value1 = Rhino.getInteger ("Please introduce the first threshold (%)to classificate the surfaces depending on the slope", 2)

value2 = Rhino.getInteger ("Please introduce the second threshold (%)to classificate the surfaces depending on the slope", 5)

value3 = Rhino.getInteger ("Please introduce the third threshold (%)to classificate the surfaces depending on the slope", 10)

value4 = Rhino.getInteger ("Please introduce the forth threshold (%)to classificate the surfaces depending on the slope", 25)

 

Dim arrSrfCloPt, arrNormal, arrProj

Dim intAngle, arrAngle, intAngleRad

Dim arrLine1(1), arrLine2(1)

Dim color

Dim intmatindex

'Variables to declare in case of wanting to insert a text

Rhino.EnableRedraw(vbFalse)

For Each strSrf In arrSrf

'we define the normal vector to the surface and its projection in the plane xy

arrSrfCloPt = Array(0,0)

arrNormal = Rhino.SurfaceNormal (strSrf, arrSrfCloPt)

arrProj = arrNormal

arrProj(0) = arrNormal(0)

arrProj(1) = arrNormal(1)

arrProj(2) = 0

 

arrLine1(0) = array(0,0,0)

arrLine1(1)= arrNormal

arrLine2(0) = array(0,0,0)

arrLine2(1) = arrProj

 

arrAngle = Rhino.Angle2(arrLine1, arrLine2)

intAngle = arrAngle(0)

 

intAngle = intAngle + 90

intAngleRad = intAngle * pi/180

       

Dim intTan, absVal

intTan = tan(intAngleRad)

absVal = abs(intTan)

 

'tan 90degrees = infinite, we have to solve this case

If intTan = pi/2 Or intTan = -pi/2 Then

absVal = 100

End If

intMatIndex = Rhino.AddMaterialToObject(strSrf)

 

If 0 <= absVal And absVal <= value1/100 Then

Color = RGB(0 , 255 , 0)

Call Rhino.MaterialColor (intMatindex, color) 

End If   

If value1/100 < absVal And absVal <= value2/100 Then

Color = RGB(125 , 255 , 0)

Call Rhino.MaterialColor (intMatindex, color)

End If

If value2/100 < absVal And absVal <= value3/100 Then

Color = RGB(255 , 255 , 0)

Call Rhino.MaterialColor (intMatindex, color)

End If

If value3/100 < absVal And absVal <= value4/100 Then

Color = RGB(255, 125 , 0)

Call Rhino.MaterialColor (intMatindex, color)

End If

If value4/100 < absVal   Then

Color = RGB(255 , 0 , 0)

Call Rhino.MaterialColor (intMatindex, color)

End If

Next

Rhino.EnableRedraw(vbTrue)

End Sub

Search Site




archi·o·logics survey

I am interested in: