分享高尔夫球的PYTHON练习,请筑梦NARUTO等高手指教
代码如下
- import rhinoscriptsyntax as rs
- import math
- def golfBall():
- sphere_radius = 21
- sphere1 = rs.AddSphere([0,0,0], sphere_radius)
- circle_radius = 1.95
- vertical_count = int( (math.pi*sphere_radius)/(2*circle_radius) )
- phi = -0.5*math.pi
- phi_step = math.pi/vertical_count
- totalCount = 0
- realCount = 0
- r2 = 4
- while phi<=0.5*math.pi:
- horizontal_count = int( (2*math.pi*math.cos(phi)*sphere_radius)/(2*circle_radius) )
- if horizontal_count==0: horizontal_count=1
- theta = 0
- theta_step = 2*math.pi/horizontal_count
- while theta<2*math.pi-1e-8:
- offset = sphere_radius + r2 - 0.4
- real_center = (offset*math.cos(theta)*math.cos(phi),
- offset*math.sin(theta)*math.cos(phi), offset*math.sin(phi))
- tempSphere = rs.AddSphere(real_center, r2)
-
- tempSphere = rs.BooleanDifference(sphere1, tempSphere)
- if tempSphere!=None:
- sphere1 = tempSphere
- realCount+=1
-
- totalCount+=1
- theta += theta_step
- phi += phi_step
- print "Total count is ", totalCount, " Real count is ", realCount
- if __name__=="__main__":
- rs.EnableRedraw(False)
- golfBall()
- rs.EnableRedraw(True)
复制代码
|
举报