Mailing List
Home
Forum Home
Softimage
Carrara
trueSpace
Dir3d-l
Maya - a powerful 3D animation and visual effects software
Macromedia Flash Development
Subjects
Cameras
scaleDown command
black out solved
Aircraft Tutorial
Mathematical XYZ ?
Its done This vs That
Its done first week
recommendations for screen video captures?
3DExplorer "Oddity "
New Director
ProTeam renewals
Fuel 's new websites (X post)
Blue peter create a make toy
targeting groups question
XPost: Shockwave 3D game ( sort of )
RES: RES: RES: Fish Modeling
Emitting particles from object intersection
Fuel 's new websites (X post)
Texturing
Big Break Contest Videos
New Plugins
Models and Texture on my updated site
Error Installing Patch tS6 6
Plasma?
Looking for Inspiration
Weird EMail Q
It 's done first week ?
Cherry not cranberry
New game
Camera Animation Problem
Particle plugins?
 
Random points on a unit sphere without biasing

Random points on a unit sphere without biasing

2005-06-14       - By Bradley R. Gabe

 Back
Reply:     1     2     3     4     5     6     7     8     9     10     >>  

It's an interesting exercise. I'm not a mathematician by any stretch, but
here's a little jscript that'll distribute points in a unit sphere by
randomly calculating a quaternion rotation, then transforming 1 unit from
origin. I use a particle cloud to visualize the point distribution.

// SPHERICAL POINT DIST
var radius = 0.5;
var pnts = 1000;

// Create New particle Type
var pTypeColl = CreateParticleType();
pType = pTypeColl(0);

// Create Cloud
var cloud = ActiveSceneRoot.AddParticleCloud();
var cloudPrim = cloud.ActivePrimitive;
cloudPrim.AddParticles(pnts, pType);
particles = cloudPrim.Particles;


// For each particle, set a random distribution
for(var i=0; i<pnts; i++){

        // Get XSIMath objects for calculating random rot
        var rot = XSIMath.CreateRotation();
        var q1 = XSIMath.CreateQuaternion();
        var trans = XSIMath.CreateTransform();
        var pos = XSIMath.CreateVector3();
        var radPos = XSIMath.CreateVector3();
        radPos.Set(radius, 0,0);

        // Calculate random quaternions
        var W = Math.random() * 2 - 1;
        var X = Math.random() * 2 - 1;
        var Y = Math.random() * 2 - 1;
        var Z = Math.random() * 2 - 1;
        q1.set(W,X,Y,Z);

        // Create a unit transform from quaternion rotation
        rot.SetFromQuaternion(q1);
        trans.SetRotation(rot);
        trans.AddLocalTranslation(radPos);
        trans.GetTranslation(pos);

        // Set particle to unit transform;
        particles(i).position = pos;

}



>Hi All,
>
>This is to the maths geniuses in the room. I want to generate X number
>of points on a unit sphere, but be sure I won't have any biasing
>involved.
>
>My first thought was just to use a couple of random numbers (let's
>assume they don't have any bias) and then use those with a few sin and
>cos function etc to generate the points. Though I have a feeling that
>would give me more points around the poles.
>
>Anyone have some good suggestions?
>
>Cheers,
>
>Alan.
>
>---
>Unsubscribe? Mail Majordomo@(protected) with the following text in body:
>unsubscribe xsi

<html>
<body>
It's an interesting exercise. I'm not a mathematician by any stretch, but
here's a little jscript that'll distribute points in a unit sphere by
randomly calculating a quaternion rotation, then transforming 1 unit from
origin. I use a particle cloud to visualize the point
distribution.<br><br>
// SPHERICAL POINT DIST<br>
<font face="Courier, Courier">var radius = 0.5;<br>
var pnts = 1000;<br><br>
// Create New particle Type<br>
var pTypeColl = CreateParticleType();<br>
pType = pTypeColl(0);<br><br>
// Create Cloud<br>
var cloud = ActiveSceneRoot.AddParticleCloud();<br>
var cloudPrim = cloud.ActivePrimitive;<br>
cloudPrim.AddParticles(pnts, pType);<br>
particles = cloudPrim.Particles;<br><br>
<br>
// For each particle, set a random distribution<br>
for(var i=0; i&lt;pnts; i++){<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab><br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>// Get
XSIMath objects for calculating random rot<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>var rot =
XSIMath.CreateRotation();<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>var q1 =
XSIMath.CreateQuaternion();<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>var trans
= XSIMath.CreateTransform();<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>var pos =
XSIMath.CreateVector3();<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>var radPos
= XSIMath.CreateVector3();<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>radPos.Set
(radius,
0,0);<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab><br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>//
Calculate random quaternions<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>var W =
Math.random() * 2 - 1;<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>var X =
Math.random() * 2 - 1;<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>var Y =
Math.random() * 2 - 1;<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>var Z =
Math.random() * 2 - 1;<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>q1.set(W,X,Y,Z);
<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab><br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>// Create
a unit transform from quaternion rotation<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>rot
.SetFromQuaternion(q1);<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>trans
.SetRotation(rot);<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>trans
.AddLocalTranslation(radPos);<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>trans
.GetTranslation(pos);<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab><br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>// Set
particle to unit transform;<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>particles(i)
.position
= pos;<br><br>
}<br><br>
<br><br>
</font><blockquote type=cite class=cite cite="">Hi All,<br><br>
This is to the maths geniuses in the room. I want to generate X
number<br>
of points on a unit sphere, but be sure I won't have any biasing<br>
involved.<br><br>
My first thought was just to use a couple of random numbers (let's<br>
assume they don't have any bias) and then use those with a few sin
and<br>
cos function etc to generate the points. Though I have a feeling
that<br>
would give me more points around the poles.<br><br>
Anyone have some good suggestions?<br><br>
Cheers,<br><br>
Alan.<br><br>
---<br>
Unsubscribe? Mail Majordomo@(protected) with the following text in
body:<br>
unsubscribe xsi</blockquote></body>
</html>