views:

213

answers:

2

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!

+2  A: 

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.

fd
Restricting the inclination to a range between 30 and 120 is getting me closer, but now I've got restricted poles on the left and right (0 and 180) and I'm trying to restrict the top and bottom (90 and 270). I tried restricting the inclination to 0-60 || 120-180 but this doesn't work, it creates a restricted band across the middle of the sphere. Please forgive my ignorance... all I know is what I read on Wikipedia!
Casey
I think I could use a rotation matrix to cheat and re-orient my restricted poles to the top and bottom, but it doesn't seem very efficient
Casey
You may just be able to swap the restriction to the azimuth instead. I have a hard time visualising which is pinned to which axis off the top of my head. If that doesn't work you either need to change your equation to specify one of the degrees of freedom to be measured as an angle from the Y-axis, or else you need that rotation.
fd
A: 

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