首页 > 代码库 > 数学图形之球面,椭球面,胶囊体,刺球.

数学图形之球面,椭球面,胶囊体,刺球.

球与圆很相关,一个是三维,一个是二维,可以参考下:圆,椭圆

 

(1)sphere的第一种写法

vertices = D1:100 D2:100t = from 0 to (PI*2) D1r = from 0 to 1 D2x = 2*r*sin(t)*sqrt(1-r^2)y = 2*r*cos(t)*sqrt(1-r^2)z = 1-2*(r^2)

 

球的网格线:


(2)sphere的另两种写法

vertices = dimension1:36 dimension2:72u = from 0 to (2*PI) dimension1v = from (-PI*0.5) to (PI*0.5) dimension2r = 10.0x = r*cos(v)*sin(u)y = r*sin(v)z = r*cos(v)*cos(u)
vertices = dimension1:36 dimension2:72u = from 0 to (2*PI) dimension1v = from 0 to (PI) dimension2r = 10.0x = r*sin(v)*sin(u)y = r*cos(v)z = r*sin(v)*cos(u)

两种写法生成的图形是一样的

 


(3)彩色球

在脚本中给rgb变量设值,就能设置顶点色.

vertices = dimension1:72 dimension2:72u = from 0 to (2*PI) dimension1v = from (-PI*0.5) to (PI*0.5) dimension2x = cos(v)*sin(u)y = sin(v)z = cos(v)*cos(u)a = 10.0r = (x+1.0)/2g = (y+1.0)/2b = (z+1.0)/2x = a*xy = a*yz = a*z


(4)圆弧面

将球的第二维度范围减小,即得到圆弧面

vertices = dimension1:36 dimension2:72u = from 0 to (2*PI) dimension1v = from (PI*0.1) to (PI*0.5) dimension2r = 10.0x = r*cos(v)*sin(u)y = r*sin(v)z = r*cos(v)*cos(u)

 

(5)椭球面

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

 

(6)胶囊体

将球面向上下两头拉伸,即得到胶囊体

 

(7)刺球

将球面上顶点到球心的距离,有规律地变化,可以得到多变的球,如刺球

vertices = dimension1:129 dimension2:65u = from 0 to (2*PI) dimension1v = from (-PI*0.5) to (PI*0.5) dimension2n =4a = from 0 to 128 D1b = from 0 to 64 D2t = (mod(a, n) + mod(b, n))/n*4r = 10.0 + tx = r*cos(v)*sin(u)y = r*sin(v)z = r*cos(v)*cos(u)