开发者

Spherical Coordinates within a range / restriction

The function below returns points on a sphere开发者_开发百科 with a given radius. I want to add restriction such that points cannot be plotted within 30 degrees of the poles of the sphere.

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;
 }

Thanks in advance!


Sounds like you can just restrict the inclination:

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

Feel free to resolve those constant values, just kept them in to show the working.


Here's what I have so far... this does what I want, restricted north and south poles. Any improvements welcome!

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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜