OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Random Point on a given Sphere

  • Thread starter Thread starter Squis
  • Start date Start date
S

Squis

Guest
I want to select random points on a given sphere. This page explains it quite well:

http://mathworld.wolfram.com/SpherePointPicking.html ("To obtain points such that any small area on the sphere...")

But I'm not entirely sure if I'm implementing it correctly in JavaScript, as I have little means of testing it properly:

Code:
var u = random();
var v = random();
var angle1 = 2 * Math.PI * u;
var angle2 = Math.pow(Math.cos (2 * v - 1), -1);
X = X0 + (radius * Math.sin(angle1) * Math.cos(angle2));
Y = Y0 + (radius * Math.sin(angle1) * Math.sin(angle1));
Z = Z0 + (radius * Math.cos(angle1));

I'm especially unsure about if I've understood that cos(-1) correctly, which I implemented as "The cosine to the power of -1".

<p>I want to select random points on a given sphere. This page explains it quite well:</p>

<p><a href="http://mathworld.wolfram.com/SpherePointPicking.html" rel="noreferrer">http://mathworld.wolfram.com/SpherePointPicking.html</a>
("To obtain points such that any small area on the sphere...")</p>

<p>But I'm not entirely sure if I'm implementing it correctly in JavaScript, as I have little means of testing it properly:</p>

<pre><code>var u = random();
var v = random();
var angle1 = 2 * Math.PI * u;
var angle2 = Math.pow(Math.cos (2 * v - 1), -1);
X = X0 + (radius * Math.sin(angle1) * Math.cos(angle2));
Y = Y0 + (radius * Math.sin(angle1) * Math.sin(angle1));
Z = Z0 + (radius * Math.cos(angle1));
</code></pre>

<p>I'm especially unsure about if I've understood that cos(-1) correctly, which I implemented as "The cosine to the power of -1".</p>
 

Latest posts

Top