首页 > 代码库 > 数学图形之圆柱面

数学图形之圆柱面

(1)圆柱面

vertices = dimension1:72 dimension2:72u = from 0 to (2*PI) dimension1v = from (-5) to (5) dimension2r = 5x = r*cos(u)y = vz = r*sin(u)

(2)任意角度圆柱面

vertices = dimension1:72 dimension2:72u = from (-5) to (5) dimension2v = from 0 to (2*PI) dimension1a = rand2(0, 2*PI)b = rand2(0, 2*PI)c = sin(v)d = cos(v)e = sin(b)f = cos(b)g = sin(a)h = cos(a)x = f*h*d - f*g*c + e*uy = g*d + h*cz = -e*h*d + e*g*c + f*ux = x*5y = y*5z = z*5

代码中会随机设置圆柱的旋转角度

(3)圆柱体

将圆柱面的两头封上,生成闭合的圆柱体

vertices = dimension1:72 dimension2:72u = from 0 to (2*PI) dimension1v = from (-5) to (5) dimension2r = if(abs(v) < 4.9, 5, 0)x = r*cos(u)y = vz = r*sin(u)

(4)由曲线生成的圆柱面

#http://www.mathcurve.com/surfaces/cylindrederevolution/cylindrederevolution.shtmlvertices = D1:100 D2:100u = from 0 to (2*PI) D1v = from 0 to (PI) D2a = rand2(1, 10)x = a*cos(u - v)z = a*sin(u - v)y = a*( u+v)

(5)鼓形

为了简单,对鼓的隆起使用了SIN函数.

vertices = dimension1:72 dimension2:72u = from 0 to (2*PI) dimension1v = from (-1) to (1) dimension2r = 5h = rand2(1, r)t = h*cos(v*PI/2)p = if(t > 0.01, r+t, 0) x = p*cos(u)y = v*hz = p*sin(u)

新的鼓形脚本,这个比上一个要圆润得多:

vertices = dimension1:72 dimension2:72u = from 0 to (2*PI) dimension1v = from (-PI/2) to (PI/2) dimension2r = 5h = rand2(1, r)t = h*cos(v)p = if(t > 0.01, r+t, 0) x = p*cos(u)y = h*sin(v)z = p*sin(u)

(6)齿轮

vertices = D1:65 D2: 4u = from 0 to (2*PI) D1v = from -1 to 1 D2k = from 0 to 64 D1m = mod(k, 2)r = 10.0 + m*2a = 0.9b = in_range(v, -a, a)x = r*sin(u)*bz = r*cos(u)*by = if(b, v, v/3)*3

(7)刺柱

vertices = D1:129 D2:65u = from 0 to (2*PI) D1v = from (-20) to (20) D2n = 4a = from 0 to 128 D1b = from 0 to 64 D2t = (mod(a, n) + mod(b, n))/n*4r = 10 + tx = r*cos(u)y = vz = r*sin(u)

(8)蛏形

vertices = D1:100 D2:100u = from 0 to (2*PI) D1v = from -5 to 5 D2r = 5x = r*cos(u)z = r*sin(u)y = x*v

(9)指定方向的圆柱(极坐标原理)

vertices = dimension1:72 dimension2:72u = from (0) to (5) dimension2v = from 0 to (2*PI) dimension1a = rand2(-2, 2)b = rand2(-2, 2)c = rand2(-2, 2)ac = sqrt(a*a + c*c)angleY = atan2(ac, b)angleXZ = atan2(a,c)m = cos(v)n = sin(v)e = sin(angleY)f = cos(angleY)g = sin(angleXZ)h = cos(angleXZ)x0 = my0 = u*f - n*ez0 = u*e + n*fx1 = x0*h + z0*gy1 = y0z1 = -x0*g + z0*hx = x1 + ay = y1 + bz = z1 + c

 

(10)指定方向的圆柱(矩阵原理)

vertices = dimension1:72 dimension2:72u = from (0) to (5) dimension2v = from 0 to (2*PI) dimension1a = rand2(-2, 2)b = rand2(-2, 2)c = rand2(-2, 2)len = sqrt(a*a + b*b + c*c)len = max(len, 0.00001)px = a/lenpy = b/lenpz = c/lenqx = 0qy = pzqz = -py len = sqrt(qx*qx + qy*qy + qz*qz)len = max(len, 0.00001)qx = qx/lenqy = qy/lenqz = qz/lenwx = py*qz - pz*qywy = pz*qx - px*qzwz = px*qy - py*qxx0 = cos(v)y0 = uz0 = sin(v)x = x0*wx + y0*px + z0*qx + ay = x0*wy + y0*py + z0*qy + bz = x0*wz + y0*pz + z0*qz + c