-1

下面的函数返回具有给定半径的球体上的点。我想添加限制,使得不能在球体两极的 30 度内绘制点。

public static function randomPoint(radius:Number):Number3D
 {

  var inclination:Number = Math.random() * Math.PI*2;
  var azimuth:Number = Math.random() * Math.PI*2;

  var point:Number3D = new Number3D(
   radius * Math.sin(inclination) * Math.cos(azimuth),
   radius * Math.sin(inclination) * Math.sin(azimuth),
   radius * Math.cos(inclination)
  );

  return point;
 }

提前致谢!

4

2 回答 2

2

听起来你可以限制倾斜:

var inclination:Number = (Math.PI/6) + Math.random()*(2*Math.PI-2*Math.PI/6)

随意解决这些常量值,只需保留它们以显示工作。

于 2010-01-04T03:06:14.537 回答
0

这是我到目前为止所拥有的......这就是我想要的,限制了北极和南极。欢迎任何改进!

var point:Number3D = sphericalPoint(100, inclination, azimuth);

public static function sphericalPoint(r:Number, inc:Number, az:Number):Number3D
{
    var point:Number3D = new Number3D(
        r * Math.sin(inc) * Math.cos(az),
        r * Math.sin(inc) * Math.sin(az),
        r * Math.cos(inc)
    );

    //cheat and use a transform matrix
    var obj:Object3D = new Object3D();
    obj.rotationX = 90;

    point.rotate(point, obj.transform);

    return point;
}

//a number between 0 and 180
protected function get inclination():Number
{
    //default
    //_inclination = Math.random() * Math.PI;

    //number between 60 and 120
    _inclination = Math.random() * (Math.PI*5/6 - Math.PI/6) + Math.PI/6;

    return _inclination;
}

//a number between 0 and 360
protected function get azimuth():Number
{
    //revolve around the Y axis
    _azimuth = Math.random() * Math.PI*2;

    return _azimuth;
}
于 2010-01-04T07:01:00.647 回答