本帖最后由 夜第七章 于 2013-2-18 22:49 编辑  
 
这是在f8的那本《rhinoscript参数建模》上的渐变倒角三角形表面代码,我不知道在Function recursivetriangle(ByVal idsrf, ByVal A, ByVal B, ByVal D)这一段中红色这一段到底是怎么回事?arrdist(2) 不就是array(distAB, distBD, distAD)中的第三天AD吗?那么执行的不就一直是“If distAD = arrdist(2) Then”这段了么? 
另外,我总觉得红色部分的byval按值传递在这里有些影响,但却一直理解不了~ 
 
 
我初学rs,对这代码里面的递归方法还是不太理解。看了很久,画了无数图了,还是不对劲,自己理解的过程和运行的过程不一致~ 
希望各位能帮我解决一下,感激不尽! 
 
 
Sub Main() 
Dim idsrf: idsrf = rhino.getobject ("select surface", 8, True, True) 
Dim udomain: udomain = rhino.surfacedomain(idsrf, 0) 
Dim vdomain: vdomain = rhino.SurfaceDomain(idsrf, 1) 
Dim u0: u0 = udomain(0) 
Dim u1: u1 = udomain(1) 
Dim v0: v0 = vdomain(0) 
Dim v1: v1 = vdomain(1) 
Dim A: A = rhino.EvaluateSurface(idsrf, array(u0,v0)) 
Dim B: B = rhino.evaluatesurface(idsrf, array(u1,v0)) 
Dim C: C = rhino.evaluatesurface(idsrf, array(u1,v1)) 
Dim D: D = rhino.EvaluateSurface(idsrf, array(u0,v1)) 
Call recursivetriangle(idsrf, A, B, D) 
Call recursivetriangle(idsrf, B, C, D) 
End Sub 
Function recursivetriangle(ByVal idsrf, ByVal A, ByVal B, ByVal D) 
Dim distAB: distAB = rhino.distance(A, B) 
Dim distBD: distBD = rhino.Distance(B, D) 
Dim distAD: distAD = rhino.Distance(A, D) 
Dim arrdist: arrdist = array(distAB, distBD, distAD) 
arrdist = rhino.sortnumbers(arrdist,True) 
Dim H,K,J 
If distAB = arrdist(2) Then 
  H = A 
  K = B 
  J = D 
End If 
If distBD = arrdist(2) Then 
  H = B 
  K = D 
  J = A 
End If 
If distAD = arrdist(2) Then 
  H = A 
  K = D 
  J = B 
End If 
Dim Z(2) 
Z(0) = (H(0)+K(0))/2 
Z(1) = (H(1)+K(1))/2 
Z(2) = (H(2)+K(2))/2 
Dim Zuv: Zuv = rhino.surfaceclosestpoint(idsrf, Z) 
Dim Zp: Zp = rhino.evaluatesurface (idsrf, Zuv) 
Dim distcurv: distcurv = rhino.distance (Zp, Z) 
Dim distang: distang = rhino.Distance (H, K) 
If (distcurv < 0.9) And (distang< 30) Then 
  Dim crv0 : crv0 = rhino.addcurve(array(A,B,D,A), 2) 
  Call rhino.SelectObject(crv0) 
  Dim pipeRadius1 
  pipeRadius1=0.9 
  rhino.Command("_Pipe" & " " & pipeRadius1 & " _Enter _Enter") 
  Rhino.UnselectAllObjects() 
Else 
  Call recursivetriangle (idsrf, H, J, Zp) 
  Call recursivetriangle (idsrf, K, J, Zp) 
End If 
End Function 
 |