webgl 球体坐标

2023-05-16  本文已影响0人  hehehehe

https://www.cnblogs.com/johnyang/p/16460456.html

image.png

上图,左图为一个球体的三维图,其中一个圆面以θ角(范围为[0,PI])的方式确定,该圆面在x-z坐标平面投影如右图,其中圆面上任意一点又由α确定(范围为[0,2PI])。
假定该球体半径为r,那么球面任意一点均可以用r,θ,α唯一确定,确定关系如下:
x=rsinθcosα;y=rcosθ;z=rsinθsinα。

      let m = 50;
      let r = 2.0;
      for (let  latitude= 0; latitude <= m; latitude++) {
        let u;
        let v;
        let x;
        let z;
        let l = r*Math.sin(Math.PI*latitude/m);
        let y = r*Math.cos(Math.PI*latitude/m);
        for(let longitude = 0; longitude <= m; longitude++){
          x = l*Math.cos(2*Math.PI*longitude/m);
          //r*Math.sin(Math.PI*latitude/m)*Math.cos(2*Math.PI*longitude/m)
          z = l*Math.sin(2*Math.PI*longitude/m);
          //纹理坐标
          u = 1-(longitude/m);  
          v = 1-(latitude/m);
          positionAndColor.push(x, y, z, u, v,x, y, z);
        }
      }
image.png
      let m = 50;
      for (let i = 0; i < m; i++) {
        for(let j = 0; j < m; j++){
          var first = (i*(m+1)) + j;
          var second = first + m + 1;
          index.push(first);
          index.push(second);
          index.push(first + 1);

          index.push(second);
          index.push(second + 1);
          index.push(first + 1);
        }
      }
上一篇 下一篇

猜你喜欢

热点阅读