Author Topic: Uniform Distribution of Points Across a Unit Sphere  (Read 1747 times)

What I need is to be able to generate random unit vectors that have a uniform average distribution across a sphere.

If I take a random azimuth (-3.14159265 to 3.14159265) and a random elevation (-1.570796325 to 1.570796325), then I have a problem. There's a higher density of points at the 'higher' elevations than there is at the 'equator'. How do I correct this problem?

Code: [Select]
function getRandomVector()
{
   %azimuth = getRandom(-314159, 314159) / 100000;
   %elevation = getRandom(-15708, 15708) / 10000;
   %z = mSin(%elevation); %scale = mCos(%elevation);
   %x = mSin(%azimuth) * %scale; %y = mCos(%azimuth) * %scale;
   return %x SPC %y SPC %z;
}

I'm guessing by the total lack of responses that no one else knows either.

It appears the forumula for polar to x-y coordinates is

x = r cos theta
y = r sin theta

and you're using..
x = cos(r) * sin theta
y = cos(r) * cos theta

(r = elevation, theta = azumith)
k what am i doing i looked up 2-d nevermind this post
« Last Edit: March 30, 2013, 02:38:12 PM by Ipquarx »

Is the magnitude of this random vector always the same? Or could it be any point within the sphere

Is the magnitude of this random vector always the same? Or could it be any point within the sphere

The vector always has a magnitude of one, yes.

Try

%x = mSin(%elevation) * mCos(%azimuth);
%y = mSin(%elevation) * mSin(%azimuth);
%z = mCos(%elevation);


Try

%x = mSin(%elevation) * mCos(%azimuth);
%y = mSin(%elevation) * mSin(%azimuth);
%z = mCos(%elevation);



Even if that were correct, then it would just reverse the problem - there would still be too many points at the 'equator' relative to the 'poles'. (And it's not correct, it would rotate the sphere to some wonky angle)

Take the arcsin of a random height from -1 to 1, then use that as the elevation? It might make them more evenly distributed vertically.
« Last Edit: March 30, 2013, 05:03:35 PM by Space Guy »

What are you actually using this for? Because if you're just trying to get a random vector, picking a random azimuth and elevation should work fine, you're thinking of this system incorrectly as a series of points when you should be assuming that it is a series of concentric circles.

If you're trying to model an actual system of finite points on the surface of circle, that's also possible but you'll need to tell us more about the sphere you're trying to model


function vectorAngle(%vector)
{
   return  0 SPC (mACos(getWord(%vector,2)/vectorDist("0 0 0",%vector))*(180/$pi)+90)%360 SPC mATan(getWord(%vector,1),getWord(%vector,0))*(180/$pi);
}

Turns vectors into angles in degrees :P
angle to vector shouldn't be hard for anyone (assuming you know basic trig)

Take the arcsin of a random height from -1 to 1, then use that as the elevation? It might make them more evenly distributed vertically.

That solved the problem; thanks! :)


angle to vector shouldn't be hard for anyone (assuming you know basic trig)

If you had actually looked at my code, you would have seen that that wasn't my question.