【问题标题】:How to fix errant orientation and points in an elliptical particle cloud?如何修复椭圆粒子云中错误的方向和点?
【发布时间】:2014-09-16 13:30:18
【问题描述】:

我正在 Three.js 中创建一个椭圆的点云,并且有两个问题看起来很简单,但我已经坚持了几天:

  1. 云应该是椭圆形的,在x 轴上具有最长轴 - 目前它以x 轴上的最短轴定向
  2. 虽然我用于云的fiddle 看起来完全是椭圆形的,但我文件中的工作代码在x 轴上的y = 0 处有几个点,它们似乎随着他们自己鼓手的节拍而运行——它们是像士兵一样排列在椭圆两侧的y = 0 上,尺寸为length(见下面的截图)。两个文件都包含相同的椭圆数学运算 - 这是怎么回事?

谢谢!

椭圆点云的代码:

particleCount = 300;
for (var p = 0; p < particleCount; p++) {
    // ELLIPTICAL
    var length = 200; // x (major axis)
    var width = 75; // y (minor axis)
    var pX = (Math.random() * length);
    // solve for length of vertical chord at pX:
    var chord;
    var rightBisector = Math.abs((length/2) - pX);
    chord = (2 * length) * Math.sqrt(1 - Math.exp(2 * Math.log(rightBisector/width)));
    var pY = (Math.random() * chord);
    pX -= length/2; // center the cloud horizontally
    pY -= chord/2; // center the cloud vertically
    // END ELLIPTICAL
    // Make image particle at pX, pY and add to system

【问题讨论】:

    标签: javascript graphics three.js geometry particle-system


    【解决方案1】:

    事实证明,所有错误都在于我对椭圆方程的误解,有人在here 上帮助了我。我已经更正了下面的代码,现在意识到我在应该使用两个不同半径的地方使用了轴的尺寸。我已经编辑了一些变量名称以使事情更清楚。

    // ELLIPTICAL particle cloud
    var majorAxis = 200; // x (major axis)
    var minorAxis = 75; // y (minor axis)
    var majorRadius = majorAxis / 2;
    var minorRadius = minorAxis / 2;
    var pX = ( Math.random() * majorAxis );
    // solve for length of vertical chord at pX:
    var rightBisector = Math.abs( majorRadius - pX );
    var chord = (2 * minorRadius) * Math.sqrt( 1 - Math.exp( 2 * Math.log( rightBisector / majorRadius ) ) );
    var pY = ( Math.random() * chord );
    pX -= majorRadius; // center the cloud horizontally
    pY -= chord / 2; // center the cloud vertically
    // END ELLIPTICAL
    // Make image particle at pX, pY and add to system
    

    现在一切正常:

    【讨论】:

      猜你喜欢
      • 2015-10-17
      • 1970-01-01
      • 2015-06-24
      • 1970-01-01
      • 2013-11-17
      • 2015-08-24
      • 2014-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多