【问题标题】:Moving point on sphere using spherical coordinates three js使用球坐标三个js在球体上移动点
【发布时间】:2019-08-09 01:51:59
【问题描述】:

我现在正在尝试在球体表面上随机移动一个点。目前我正在尝试通过生成随机球坐标然后使用函数.setFromSphericalCoords()将这些坐标转换为3d位置来做到这一点

这就是每帧生成一个新的随机球坐标的代码:

element.kralenSpherical.phi += Math.random() * 2 -1;
if(element.kralenSpherical.phi <= 0 ) element.kralenSpherical.phi = 0;
else if(element.kralenSpherical.phi >= 180 ) element.kralenSpherical.phi = 180;
element.kralenSpherical.theta += Math.random() * 2 -1;
if(element.kralenSpherical.theta >= 360 ) element.kralenSpherical.theta = 0;
else if(element.kralenSpherical.theta <= 0) element.kralenSpherical.theta = 360;

element.kraal.position.copy(element.BaseLocation.clone().add(sphericalVector.setFromSphericalCoords(element.kralenSpherical.radius, element.kralenSpherical.phi, element.kralenSpherical.theta)));

这有点工作,但目前我的球体点并没有真正在球体上移动,而是跳跃了很远的距离。

我认为这与我作为phitheta 提供的值有关,但问题是我不知道phitheta 的值范围是什么。

如果有不清楚的地方,请告诉我,以便我澄清!

【问题讨论】:

    标签: javascript three.js 3d spherical-coordinate


    【解决方案1】:

    不是three.js,但这应该很容易翻译。 众所周知,这是处理:

    
    
    void setup() {
      size(300, 300, P3D);  
      frameRate(300);
      background(0);
    }
    
    void draw() {
    
      lights();
      translate(width/2, height/2);
      stroke(255,255,0);
      noFill();
      //sphere(75);
    
      PVector v = noise_spherical_point(frameCount * 0.009, 75);
    
      translate(v.x, v.y, v.z);
      fill(255,0,0);
      noStroke();
      sphere(1);
    
    }
    
    
    PVector noise_spherical_point(float t, float rad) {
      float x = noise(t) * 2 -1;
      float y = noise(0, t)  * 2 -1;
      float z = noise(0, 0, t) * 2 -1;
      PVector v = new PVector(x, y, z);
      v = v.normalize();
      v.mult(rad);
      return v;
    }
    

    【讨论】:

      【解决方案2】:

      这是因为phitheta 的单位是弧度,而不是度数。

      所以Math.random() * 2 -1 对弧度来说太大了。

      根据current implementaion,这些参数似乎没有范围限制。

      【讨论】:

      • 好的,他们使用什么范围的弧度?或者他们不使用任何范围?
      猜你喜欢
      • 2021-11-18
      • 2017-11-13
      • 1970-01-01
      • 2013-08-16
      • 1970-01-01
      • 2021-11-27
      • 2011-12-12
      • 2020-02-19
      • 2014-01-27
      相关资源
      最近更新 更多