2010-01-04 115 views
-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; 
} 

在此先感谢!

+2

随时可以这样做。有问题吗? – 2010-01-04 03:01:01

+0

含义是我不知道如何添加这种限制功能。下次我会确保使用问号。感谢Nick Veys。 – Casey 2010-01-04 08:29:06

回答

2

听起来像是你可以限制倾角:

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

随意解决这些常数值,只是不停地在他们表现出的工作。

+0

将倾向限制在30到120之间会让我更加接近,但是现在我已经在左侧和右侧(0和180)限制了杆,并且我试图限制顶部和底部(90和270) 。我试图限制倾向0-60 || 120-180但这不起作用,它会在球体中间创建一个限制带。请原谅我的无知......我所知道的是我在维基百科上阅读的内容! – Casey 2010-01-04 06:50:24

+0

我想我可以使用旋转矩阵来欺骗并重新定位我的受限制杆到顶部和底部,但它看起来效率不高 – Casey 2010-01-04 06:51:50

+0

您可能只需将限制交换为方位角即可。我很难看出哪个轴被固定在我头顶的哪个轴上。如果这不起作用,您或者需要改变方程式来指定要作为Y轴角度测量的自由度之一,否则您需要该旋转。 – 2010-01-04 10:27:58

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