How to generate random points on a sphere?
How do I generate $1000$ points $(x, y, z)$ and make sure they land on a sphere whose center is $(0, 0, 0)$ and its diameter is $20$? Simply, how do I manipulate a point's coordinates so that the point lies on the sphere's "surface"?
geometry computational-geometry spherical-geometry
|
show 7 more comments
How do I generate $1000$ points $(x, y, z)$ and make sure they land on a sphere whose center is $(0, 0, 0)$ and its diameter is $20$? Simply, how do I manipulate a point's coordinates so that the point lies on the sphere's "surface"?
geometry computational-geometry spherical-geometry
4
Simply Pythagorean theorem?
– MonkeyKing
Dec 22 '15 at 20:31
4
do you want the points to be uniformly random on the surface of the sphere?
– Alex R.
Dec 22 '15 at 20:33
8
Possible duplicate of Picking random points in the volume of sphere with uniform probability
– leonbloy
Dec 22 '15 at 20:42
7
@leonbloy: Not a duplicate, since that one was for the solid sphere.
– Brian M. Scott
Dec 22 '15 at 22:39
4
This is the correct duplicate: How can I pick a random point on the surface of a sphere with equal distribution? But the answers here are better (although they are mostly covered by the MathWorld article I linked above).
– Rahul
Dec 23 '15 at 1:04
|
show 7 more comments
How do I generate $1000$ points $(x, y, z)$ and make sure they land on a sphere whose center is $(0, 0, 0)$ and its diameter is $20$? Simply, how do I manipulate a point's coordinates so that the point lies on the sphere's "surface"?
geometry computational-geometry spherical-geometry
How do I generate $1000$ points $(x, y, z)$ and make sure they land on a sphere whose center is $(0, 0, 0)$ and its diameter is $20$? Simply, how do I manipulate a point's coordinates so that the point lies on the sphere's "surface"?
geometry computational-geometry spherical-geometry
geometry computational-geometry spherical-geometry
edited Mar 23 '18 at 20:23
Rodrigo de Azevedo
12.8k41855
12.8k41855
asked Dec 22 '15 at 20:29
Filip
194125
194125
4
Simply Pythagorean theorem?
– MonkeyKing
Dec 22 '15 at 20:31
4
do you want the points to be uniformly random on the surface of the sphere?
– Alex R.
Dec 22 '15 at 20:33
8
Possible duplicate of Picking random points in the volume of sphere with uniform probability
– leonbloy
Dec 22 '15 at 20:42
7
@leonbloy: Not a duplicate, since that one was for the solid sphere.
– Brian M. Scott
Dec 22 '15 at 22:39
4
This is the correct duplicate: How can I pick a random point on the surface of a sphere with equal distribution? But the answers here are better (although they are mostly covered by the MathWorld article I linked above).
– Rahul
Dec 23 '15 at 1:04
|
show 7 more comments
4
Simply Pythagorean theorem?
– MonkeyKing
Dec 22 '15 at 20:31
4
do you want the points to be uniformly random on the surface of the sphere?
– Alex R.
Dec 22 '15 at 20:33
8
Possible duplicate of Picking random points in the volume of sphere with uniform probability
– leonbloy
Dec 22 '15 at 20:42
7
@leonbloy: Not a duplicate, since that one was for the solid sphere.
– Brian M. Scott
Dec 22 '15 at 22:39
4
This is the correct duplicate: How can I pick a random point on the surface of a sphere with equal distribution? But the answers here are better (although they are mostly covered by the MathWorld article I linked above).
– Rahul
Dec 23 '15 at 1:04
4
4
Simply Pythagorean theorem?
– MonkeyKing
Dec 22 '15 at 20:31
Simply Pythagorean theorem?
– MonkeyKing
Dec 22 '15 at 20:31
4
4
do you want the points to be uniformly random on the surface of the sphere?
– Alex R.
Dec 22 '15 at 20:33
do you want the points to be uniformly random on the surface of the sphere?
– Alex R.
Dec 22 '15 at 20:33
8
8
Possible duplicate of Picking random points in the volume of sphere with uniform probability
– leonbloy
Dec 22 '15 at 20:42
Possible duplicate of Picking random points in the volume of sphere with uniform probability
– leonbloy
Dec 22 '15 at 20:42
7
7
@leonbloy: Not a duplicate, since that one was for the solid sphere.
– Brian M. Scott
Dec 22 '15 at 22:39
@leonbloy: Not a duplicate, since that one was for the solid sphere.
– Brian M. Scott
Dec 22 '15 at 22:39
4
4
This is the correct duplicate: How can I pick a random point on the surface of a sphere with equal distribution? But the answers here are better (although they are mostly covered by the MathWorld article I linked above).
– Rahul
Dec 23 '15 at 1:04
This is the correct duplicate: How can I pick a random point on the surface of a sphere with equal distribution? But the answers here are better (although they are mostly covered by the MathWorld article I linked above).
– Rahul
Dec 23 '15 at 1:04
|
show 7 more comments
6 Answers
6
active
oldest
votes
Use the fact that if you cut a sphere of a given radius with two parallel planes, the area of the strip of spherical surface between the planes depends only on the distance between the planes, not on where they cut the sphere. Thus, you can get a uniform distribution on the surface using two uniformly distributed random variables:
- a $z$-coordinate, which in your case should be chosen between $-10$ and $10$; and
- an angle in $[0,2pi)$ corresponding to a longitude.
From those it’s straightforward to generate the $x$- and $y$-coordinates.
12
This always challenges my intuition.
– copper.hat
Dec 22 '15 at 21:17
1
@copper.hat: Yes, I’ve always found it surprising that the flattening and stretching exactly balance the shrinking radius as the planes move towards a pole.
– Brian M. Scott
Dec 22 '15 at 21:22
1
So you should get a uniform distribution on the cylinder and project on the sphere, like Archimedes. Nice!
– Orest Bucicovschi
Dec 22 '15 at 22:37
3
This proves, by the way, that the surface area of a sphere's circumscribing cylinder (minus the endcaps) equals that of the sphere itself (and by corollary, the volume of the sphere is one-third the radius times the common surface area).
– Brian Tung
Dec 23 '15 at 0:11
4
Does this generalize to higher dimensions? For a 2D circle you just pick $theta$ uniformly. For a 3D sphere you choose a $theta$ and $z$. Is there a similar result for 4D and higher?
– Meni Rosenfeld
Dec 23 '15 at 13:07
|
show 7 more comments
Using Gaussian distribution for all three coordinates of your point will ensure an uniform distribution on the surface of the sphere. You should proceed as follows
- Generate three random numbers $x, y, z$ using Gaussian distribution
- Multiply each number by $1/sqrt{x^2+y^2+z^2}$ (a.k.a. Normalise) . You should handle what happens if $x=y=z=0$.
- Multiply each number by the radius of your sphere.
1
Excellent! This works in any dimension and seems not to be widely known, although I've seen some older paper (late $'40$'s) where the authors claim that they've learned it from Harald Cramér.
– Orest Bucicovschi
Dec 22 '15 at 22:43
21
Not widely known? Every probabilist should know that the multivariate standard normal distribution is spherically symmetric, from which this follows immediately.
– Robert Israel
Dec 23 '15 at 0:40
add a comment |
Here is a simple but less efficient way:
Generate points uniformly $x in [-10,10]^3$ and reject if $|x| =0 $ (which
should rarely happen) or
$|x| > 10$ (which should happen with probability ${20^3 -{4 over 3} pi 10^3 over 20^3} =1 - {pi over 6} approx 48%$).
Otherwise let $y = {10 over |x|} x$. Then $y$ will be distributed uniformly on the surface of the $10$-sphere.
The points that are not rejected are uniformly distributed in the sphere, and projecting such points to the surface preserves uniformity.
– copper.hat
Dec 22 '15 at 22:48
This method is probably faster than the others from a computationnal point of view. The only complex operations are a division and a square root, and both are quite fast
– Tryss
Dec 23 '15 at 21:34
@Tryss Computationally, yes, but probabilistically the rejection rate is not to be ignored, especially in high dimensions (cf. curse of dimensionality). There are also quite fast implementations of standard normal random variates. It may be worth doing some simulations although I would be surprised if no one has written a paper about it.
– heropup
Dec 23 '15 at 22:11
I think for 1000 points the cost is minimal, and the coding fairly simple.
– copper.hat
Dec 23 '15 at 22:13
@heropup : yes, in high dimensions the rejection rate is big, and the gaussian method scale lineary contrary to this method. But in low dimensions, it works very well
– Tryss
Dec 23 '15 at 22:30
add a comment |
In addition to Brian Scott's excellent and clever answer, here's another, more straightforward way (in case you want to approach it with a geographical intuition): From two random variables $u_1, u_2$, distributed uniformly on the interval $[0, 1]$, generate (in radians) the latitude
$$
lambda = arccos (2u_1-1)-frac{pi}{2}
$$
and the longitude
$$
phi = 2pi u_2
$$
Then compute the rectangular coordinates accordingly:
$$
x = coslambdacosphi
$$
$$
y = coslambdasinphi
$$
$$
z = sinlambda
$$
ETA (thanks to Tanner Strunk—see comments): This will give coordinates of points on the unit sphere. To have them land on the sphere with diameter $20$ (and therefore radius $10$), simply multiply each by $10$.
This is the best way. Some points: 1. arccos(-1..1) normally gives the range 0..pi, so I would be inclined to subtract pi/2 instead of pi, to get a number in the range -pi/2 .. pi/2 which is how a geographer would present the angle. Actually I think this change is required, because the current answer will always give negative z. 2. Having done that, I see nothing wrong with z = 2u -1 and cos lamba = sqrt(1-z^2) 3. phi works just as well with 2*npiu2, which may be convenient in some computer implementations.
– Level River St
Dec 24 '15 at 11:06
Oops, I think you are right. Thanks for the look out.
– Brian Tung
Dec 24 '15 at 15:41
1
I'm a bit late in coming to this question (ha), but you should be scaling those x,y,z expressions by 10 to land on the sphere, right? (Tiny, nit-picky detail, but I figure it should be noted for future readers.) Nice avatar by the way, Brian.
– Tanner Strunk
Jan 11 '18 at 17:33
1
@TannerStrunk: Yes, you're quite right, thanks! I'll add an edit.
– Brian Tung
Jan 11 '18 at 18:35
add a comment |
Same way as on a real sphere, but $(x,y,z) $ multiplied by $i.$
5
I'm afraid the OP by "imaginary" just meant "mathematical"
– leonbloy
Dec 22 '15 at 20:43
3
That's funny! ${}{}$
– copper.hat
Dec 22 '15 at 20:54
May have been edited on 23 March 2015 to remove "imaginary"
– Narasimham
Dec 23 '18 at 10:38
add a comment |
Wolfram Mathworld provides a methodology for randomly picking a point on a sphere:
To obtain points such that any small area on the sphere is expected to contain the same number of points, choose $u$ and $ν$ to be random variates on $[0,1]$. Then: $$begin{array}{ll}theta=2pi u\
varphi= arccos(2v - 1)end{array}$$ gives the spherical coordinates for a set of points which are uniformly distributed over $mathbb{S}^2$.
1
Except for the link, this seems to be exactly the same as Brian Tung's earlier answer.
– Ilmari Karonen
Dec 23 '15 at 18:39
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f1585975%2fhow-to-generate-random-points-on-a-sphere%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use the fact that if you cut a sphere of a given radius with two parallel planes, the area of the strip of spherical surface between the planes depends only on the distance between the planes, not on where they cut the sphere. Thus, you can get a uniform distribution on the surface using two uniformly distributed random variables:
- a $z$-coordinate, which in your case should be chosen between $-10$ and $10$; and
- an angle in $[0,2pi)$ corresponding to a longitude.
From those it’s straightforward to generate the $x$- and $y$-coordinates.
12
This always challenges my intuition.
– copper.hat
Dec 22 '15 at 21:17
1
@copper.hat: Yes, I’ve always found it surprising that the flattening and stretching exactly balance the shrinking radius as the planes move towards a pole.
– Brian M. Scott
Dec 22 '15 at 21:22
1
So you should get a uniform distribution on the cylinder and project on the sphere, like Archimedes. Nice!
– Orest Bucicovschi
Dec 22 '15 at 22:37
3
This proves, by the way, that the surface area of a sphere's circumscribing cylinder (minus the endcaps) equals that of the sphere itself (and by corollary, the volume of the sphere is one-third the radius times the common surface area).
– Brian Tung
Dec 23 '15 at 0:11
4
Does this generalize to higher dimensions? For a 2D circle you just pick $theta$ uniformly. For a 3D sphere you choose a $theta$ and $z$. Is there a similar result for 4D and higher?
– Meni Rosenfeld
Dec 23 '15 at 13:07
|
show 7 more comments
Use the fact that if you cut a sphere of a given radius with two parallel planes, the area of the strip of spherical surface between the planes depends only on the distance between the planes, not on where they cut the sphere. Thus, you can get a uniform distribution on the surface using two uniformly distributed random variables:
- a $z$-coordinate, which in your case should be chosen between $-10$ and $10$; and
- an angle in $[0,2pi)$ corresponding to a longitude.
From those it’s straightforward to generate the $x$- and $y$-coordinates.
12
This always challenges my intuition.
– copper.hat
Dec 22 '15 at 21:17
1
@copper.hat: Yes, I’ve always found it surprising that the flattening and stretching exactly balance the shrinking radius as the planes move towards a pole.
– Brian M. Scott
Dec 22 '15 at 21:22
1
So you should get a uniform distribution on the cylinder and project on the sphere, like Archimedes. Nice!
– Orest Bucicovschi
Dec 22 '15 at 22:37
3
This proves, by the way, that the surface area of a sphere's circumscribing cylinder (minus the endcaps) equals that of the sphere itself (and by corollary, the volume of the sphere is one-third the radius times the common surface area).
– Brian Tung
Dec 23 '15 at 0:11
4
Does this generalize to higher dimensions? For a 2D circle you just pick $theta$ uniformly. For a 3D sphere you choose a $theta$ and $z$. Is there a similar result for 4D and higher?
– Meni Rosenfeld
Dec 23 '15 at 13:07
|
show 7 more comments
Use the fact that if you cut a sphere of a given radius with two parallel planes, the area of the strip of spherical surface between the planes depends only on the distance between the planes, not on where they cut the sphere. Thus, you can get a uniform distribution on the surface using two uniformly distributed random variables:
- a $z$-coordinate, which in your case should be chosen between $-10$ and $10$; and
- an angle in $[0,2pi)$ corresponding to a longitude.
From those it’s straightforward to generate the $x$- and $y$-coordinates.
Use the fact that if you cut a sphere of a given radius with two parallel planes, the area of the strip of spherical surface between the planes depends only on the distance between the planes, not on where they cut the sphere. Thus, you can get a uniform distribution on the surface using two uniformly distributed random variables:
- a $z$-coordinate, which in your case should be chosen between $-10$ and $10$; and
- an angle in $[0,2pi)$ corresponding to a longitude.
From those it’s straightforward to generate the $x$- and $y$-coordinates.
answered Dec 22 '15 at 21:05
Brian M. Scott
455k38505907
455k38505907
12
This always challenges my intuition.
– copper.hat
Dec 22 '15 at 21:17
1
@copper.hat: Yes, I’ve always found it surprising that the flattening and stretching exactly balance the shrinking radius as the planes move towards a pole.
– Brian M. Scott
Dec 22 '15 at 21:22
1
So you should get a uniform distribution on the cylinder and project on the sphere, like Archimedes. Nice!
– Orest Bucicovschi
Dec 22 '15 at 22:37
3
This proves, by the way, that the surface area of a sphere's circumscribing cylinder (minus the endcaps) equals that of the sphere itself (and by corollary, the volume of the sphere is one-third the radius times the common surface area).
– Brian Tung
Dec 23 '15 at 0:11
4
Does this generalize to higher dimensions? For a 2D circle you just pick $theta$ uniformly. For a 3D sphere you choose a $theta$ and $z$. Is there a similar result for 4D and higher?
– Meni Rosenfeld
Dec 23 '15 at 13:07
|
show 7 more comments
12
This always challenges my intuition.
– copper.hat
Dec 22 '15 at 21:17
1
@copper.hat: Yes, I’ve always found it surprising that the flattening and stretching exactly balance the shrinking radius as the planes move towards a pole.
– Brian M. Scott
Dec 22 '15 at 21:22
1
So you should get a uniform distribution on the cylinder and project on the sphere, like Archimedes. Nice!
– Orest Bucicovschi
Dec 22 '15 at 22:37
3
This proves, by the way, that the surface area of a sphere's circumscribing cylinder (minus the endcaps) equals that of the sphere itself (and by corollary, the volume of the sphere is one-third the radius times the common surface area).
– Brian Tung
Dec 23 '15 at 0:11
4
Does this generalize to higher dimensions? For a 2D circle you just pick $theta$ uniformly. For a 3D sphere you choose a $theta$ and $z$. Is there a similar result for 4D and higher?
– Meni Rosenfeld
Dec 23 '15 at 13:07
12
12
This always challenges my intuition.
– copper.hat
Dec 22 '15 at 21:17
This always challenges my intuition.
– copper.hat
Dec 22 '15 at 21:17
1
1
@copper.hat: Yes, I’ve always found it surprising that the flattening and stretching exactly balance the shrinking radius as the planes move towards a pole.
– Brian M. Scott
Dec 22 '15 at 21:22
@copper.hat: Yes, I’ve always found it surprising that the flattening and stretching exactly balance the shrinking radius as the planes move towards a pole.
– Brian M. Scott
Dec 22 '15 at 21:22
1
1
So you should get a uniform distribution on the cylinder and project on the sphere, like Archimedes. Nice!
– Orest Bucicovschi
Dec 22 '15 at 22:37
So you should get a uniform distribution on the cylinder and project on the sphere, like Archimedes. Nice!
– Orest Bucicovschi
Dec 22 '15 at 22:37
3
3
This proves, by the way, that the surface area of a sphere's circumscribing cylinder (minus the endcaps) equals that of the sphere itself (and by corollary, the volume of the sphere is one-third the radius times the common surface area).
– Brian Tung
Dec 23 '15 at 0:11
This proves, by the way, that the surface area of a sphere's circumscribing cylinder (minus the endcaps) equals that of the sphere itself (and by corollary, the volume of the sphere is one-third the radius times the common surface area).
– Brian Tung
Dec 23 '15 at 0:11
4
4
Does this generalize to higher dimensions? For a 2D circle you just pick $theta$ uniformly. For a 3D sphere you choose a $theta$ and $z$. Is there a similar result for 4D and higher?
– Meni Rosenfeld
Dec 23 '15 at 13:07
Does this generalize to higher dimensions? For a 2D circle you just pick $theta$ uniformly. For a 3D sphere you choose a $theta$ and $z$. Is there a similar result for 4D and higher?
– Meni Rosenfeld
Dec 23 '15 at 13:07
|
show 7 more comments
Using Gaussian distribution for all three coordinates of your point will ensure an uniform distribution on the surface of the sphere. You should proceed as follows
- Generate three random numbers $x, y, z$ using Gaussian distribution
- Multiply each number by $1/sqrt{x^2+y^2+z^2}$ (a.k.a. Normalise) . You should handle what happens if $x=y=z=0$.
- Multiply each number by the radius of your sphere.
1
Excellent! This works in any dimension and seems not to be widely known, although I've seen some older paper (late $'40$'s) where the authors claim that they've learned it from Harald Cramér.
– Orest Bucicovschi
Dec 22 '15 at 22:43
21
Not widely known? Every probabilist should know that the multivariate standard normal distribution is spherically symmetric, from which this follows immediately.
– Robert Israel
Dec 23 '15 at 0:40
add a comment |
Using Gaussian distribution for all three coordinates of your point will ensure an uniform distribution on the surface of the sphere. You should proceed as follows
- Generate three random numbers $x, y, z$ using Gaussian distribution
- Multiply each number by $1/sqrt{x^2+y^2+z^2}$ (a.k.a. Normalise) . You should handle what happens if $x=y=z=0$.
- Multiply each number by the radius of your sphere.
1
Excellent! This works in any dimension and seems not to be widely known, although I've seen some older paper (late $'40$'s) where the authors claim that they've learned it from Harald Cramér.
– Orest Bucicovschi
Dec 22 '15 at 22:43
21
Not widely known? Every probabilist should know that the multivariate standard normal distribution is spherically symmetric, from which this follows immediately.
– Robert Israel
Dec 23 '15 at 0:40
add a comment |
Using Gaussian distribution for all three coordinates of your point will ensure an uniform distribution on the surface of the sphere. You should proceed as follows
- Generate three random numbers $x, y, z$ using Gaussian distribution
- Multiply each number by $1/sqrt{x^2+y^2+z^2}$ (a.k.a. Normalise) . You should handle what happens if $x=y=z=0$.
- Multiply each number by the radius of your sphere.
Using Gaussian distribution for all three coordinates of your point will ensure an uniform distribution on the surface of the sphere. You should proceed as follows
- Generate three random numbers $x, y, z$ using Gaussian distribution
- Multiply each number by $1/sqrt{x^2+y^2+z^2}$ (a.k.a. Normalise) . You should handle what happens if $x=y=z=0$.
- Multiply each number by the radius of your sphere.
edited May 23 '17 at 12:39
Community♦
1
1
answered Dec 22 '15 at 20:40
Henricus V.
15k21947
15k21947
1
Excellent! This works in any dimension and seems not to be widely known, although I've seen some older paper (late $'40$'s) where the authors claim that they've learned it from Harald Cramér.
– Orest Bucicovschi
Dec 22 '15 at 22:43
21
Not widely known? Every probabilist should know that the multivariate standard normal distribution is spherically symmetric, from which this follows immediately.
– Robert Israel
Dec 23 '15 at 0:40
add a comment |
1
Excellent! This works in any dimension and seems not to be widely known, although I've seen some older paper (late $'40$'s) where the authors claim that they've learned it from Harald Cramér.
– Orest Bucicovschi
Dec 22 '15 at 22:43
21
Not widely known? Every probabilist should know that the multivariate standard normal distribution is spherically symmetric, from which this follows immediately.
– Robert Israel
Dec 23 '15 at 0:40
1
1
Excellent! This works in any dimension and seems not to be widely known, although I've seen some older paper (late $'40$'s) where the authors claim that they've learned it from Harald Cramér.
– Orest Bucicovschi
Dec 22 '15 at 22:43
Excellent! This works in any dimension and seems not to be widely known, although I've seen some older paper (late $'40$'s) where the authors claim that they've learned it from Harald Cramér.
– Orest Bucicovschi
Dec 22 '15 at 22:43
21
21
Not widely known? Every probabilist should know that the multivariate standard normal distribution is spherically symmetric, from which this follows immediately.
– Robert Israel
Dec 23 '15 at 0:40
Not widely known? Every probabilist should know that the multivariate standard normal distribution is spherically symmetric, from which this follows immediately.
– Robert Israel
Dec 23 '15 at 0:40
add a comment |
Here is a simple but less efficient way:
Generate points uniformly $x in [-10,10]^3$ and reject if $|x| =0 $ (which
should rarely happen) or
$|x| > 10$ (which should happen with probability ${20^3 -{4 over 3} pi 10^3 over 20^3} =1 - {pi over 6} approx 48%$).
Otherwise let $y = {10 over |x|} x$. Then $y$ will be distributed uniformly on the surface of the $10$-sphere.
The points that are not rejected are uniformly distributed in the sphere, and projecting such points to the surface preserves uniformity.
– copper.hat
Dec 22 '15 at 22:48
This method is probably faster than the others from a computationnal point of view. The only complex operations are a division and a square root, and both are quite fast
– Tryss
Dec 23 '15 at 21:34
@Tryss Computationally, yes, but probabilistically the rejection rate is not to be ignored, especially in high dimensions (cf. curse of dimensionality). There are also quite fast implementations of standard normal random variates. It may be worth doing some simulations although I would be surprised if no one has written a paper about it.
– heropup
Dec 23 '15 at 22:11
I think for 1000 points the cost is minimal, and the coding fairly simple.
– copper.hat
Dec 23 '15 at 22:13
@heropup : yes, in high dimensions the rejection rate is big, and the gaussian method scale lineary contrary to this method. But in low dimensions, it works very well
– Tryss
Dec 23 '15 at 22:30
add a comment |
Here is a simple but less efficient way:
Generate points uniformly $x in [-10,10]^3$ and reject if $|x| =0 $ (which
should rarely happen) or
$|x| > 10$ (which should happen with probability ${20^3 -{4 over 3} pi 10^3 over 20^3} =1 - {pi over 6} approx 48%$).
Otherwise let $y = {10 over |x|} x$. Then $y$ will be distributed uniformly on the surface of the $10$-sphere.
The points that are not rejected are uniformly distributed in the sphere, and projecting such points to the surface preserves uniformity.
– copper.hat
Dec 22 '15 at 22:48
This method is probably faster than the others from a computationnal point of view. The only complex operations are a division and a square root, and both are quite fast
– Tryss
Dec 23 '15 at 21:34
@Tryss Computationally, yes, but probabilistically the rejection rate is not to be ignored, especially in high dimensions (cf. curse of dimensionality). There are also quite fast implementations of standard normal random variates. It may be worth doing some simulations although I would be surprised if no one has written a paper about it.
– heropup
Dec 23 '15 at 22:11
I think for 1000 points the cost is minimal, and the coding fairly simple.
– copper.hat
Dec 23 '15 at 22:13
@heropup : yes, in high dimensions the rejection rate is big, and the gaussian method scale lineary contrary to this method. But in low dimensions, it works very well
– Tryss
Dec 23 '15 at 22:30
add a comment |
Here is a simple but less efficient way:
Generate points uniformly $x in [-10,10]^3$ and reject if $|x| =0 $ (which
should rarely happen) or
$|x| > 10$ (which should happen with probability ${20^3 -{4 over 3} pi 10^3 over 20^3} =1 - {pi over 6} approx 48%$).
Otherwise let $y = {10 over |x|} x$. Then $y$ will be distributed uniformly on the surface of the $10$-sphere.
Here is a simple but less efficient way:
Generate points uniformly $x in [-10,10]^3$ and reject if $|x| =0 $ (which
should rarely happen) or
$|x| > 10$ (which should happen with probability ${20^3 -{4 over 3} pi 10^3 over 20^3} =1 - {pi over 6} approx 48%$).
Otherwise let $y = {10 over |x|} x$. Then $y$ will be distributed uniformly on the surface of the $10$-sphere.
edited Dec 22 '15 at 21:14
answered Dec 22 '15 at 21:01
copper.hat
126k559159
126k559159
The points that are not rejected are uniformly distributed in the sphere, and projecting such points to the surface preserves uniformity.
– copper.hat
Dec 22 '15 at 22:48
This method is probably faster than the others from a computationnal point of view. The only complex operations are a division and a square root, and both are quite fast
– Tryss
Dec 23 '15 at 21:34
@Tryss Computationally, yes, but probabilistically the rejection rate is not to be ignored, especially in high dimensions (cf. curse of dimensionality). There are also quite fast implementations of standard normal random variates. It may be worth doing some simulations although I would be surprised if no one has written a paper about it.
– heropup
Dec 23 '15 at 22:11
I think for 1000 points the cost is minimal, and the coding fairly simple.
– copper.hat
Dec 23 '15 at 22:13
@heropup : yes, in high dimensions the rejection rate is big, and the gaussian method scale lineary contrary to this method. But in low dimensions, it works very well
– Tryss
Dec 23 '15 at 22:30
add a comment |
The points that are not rejected are uniformly distributed in the sphere, and projecting such points to the surface preserves uniformity.
– copper.hat
Dec 22 '15 at 22:48
This method is probably faster than the others from a computationnal point of view. The only complex operations are a division and a square root, and both are quite fast
– Tryss
Dec 23 '15 at 21:34
@Tryss Computationally, yes, but probabilistically the rejection rate is not to be ignored, especially in high dimensions (cf. curse of dimensionality). There are also quite fast implementations of standard normal random variates. It may be worth doing some simulations although I would be surprised if no one has written a paper about it.
– heropup
Dec 23 '15 at 22:11
I think for 1000 points the cost is minimal, and the coding fairly simple.
– copper.hat
Dec 23 '15 at 22:13
@heropup : yes, in high dimensions the rejection rate is big, and the gaussian method scale lineary contrary to this method. But in low dimensions, it works very well
– Tryss
Dec 23 '15 at 22:30
The points that are not rejected are uniformly distributed in the sphere, and projecting such points to the surface preserves uniformity.
– copper.hat
Dec 22 '15 at 22:48
The points that are not rejected are uniformly distributed in the sphere, and projecting such points to the surface preserves uniformity.
– copper.hat
Dec 22 '15 at 22:48
This method is probably faster than the others from a computationnal point of view. The only complex operations are a division and a square root, and both are quite fast
– Tryss
Dec 23 '15 at 21:34
This method is probably faster than the others from a computationnal point of view. The only complex operations are a division and a square root, and both are quite fast
– Tryss
Dec 23 '15 at 21:34
@Tryss Computationally, yes, but probabilistically the rejection rate is not to be ignored, especially in high dimensions (cf. curse of dimensionality). There are also quite fast implementations of standard normal random variates. It may be worth doing some simulations although I would be surprised if no one has written a paper about it.
– heropup
Dec 23 '15 at 22:11
@Tryss Computationally, yes, but probabilistically the rejection rate is not to be ignored, especially in high dimensions (cf. curse of dimensionality). There are also quite fast implementations of standard normal random variates. It may be worth doing some simulations although I would be surprised if no one has written a paper about it.
– heropup
Dec 23 '15 at 22:11
I think for 1000 points the cost is minimal, and the coding fairly simple.
– copper.hat
Dec 23 '15 at 22:13
I think for 1000 points the cost is minimal, and the coding fairly simple.
– copper.hat
Dec 23 '15 at 22:13
@heropup : yes, in high dimensions the rejection rate is big, and the gaussian method scale lineary contrary to this method. But in low dimensions, it works very well
– Tryss
Dec 23 '15 at 22:30
@heropup : yes, in high dimensions the rejection rate is big, and the gaussian method scale lineary contrary to this method. But in low dimensions, it works very well
– Tryss
Dec 23 '15 at 22:30
add a comment |
In addition to Brian Scott's excellent and clever answer, here's another, more straightforward way (in case you want to approach it with a geographical intuition): From two random variables $u_1, u_2$, distributed uniformly on the interval $[0, 1]$, generate (in radians) the latitude
$$
lambda = arccos (2u_1-1)-frac{pi}{2}
$$
and the longitude
$$
phi = 2pi u_2
$$
Then compute the rectangular coordinates accordingly:
$$
x = coslambdacosphi
$$
$$
y = coslambdasinphi
$$
$$
z = sinlambda
$$
ETA (thanks to Tanner Strunk—see comments): This will give coordinates of points on the unit sphere. To have them land on the sphere with diameter $20$ (and therefore radius $10$), simply multiply each by $10$.
This is the best way. Some points: 1. arccos(-1..1) normally gives the range 0..pi, so I would be inclined to subtract pi/2 instead of pi, to get a number in the range -pi/2 .. pi/2 which is how a geographer would present the angle. Actually I think this change is required, because the current answer will always give negative z. 2. Having done that, I see nothing wrong with z = 2u -1 and cos lamba = sqrt(1-z^2) 3. phi works just as well with 2*npiu2, which may be convenient in some computer implementations.
– Level River St
Dec 24 '15 at 11:06
Oops, I think you are right. Thanks for the look out.
– Brian Tung
Dec 24 '15 at 15:41
1
I'm a bit late in coming to this question (ha), but you should be scaling those x,y,z expressions by 10 to land on the sphere, right? (Tiny, nit-picky detail, but I figure it should be noted for future readers.) Nice avatar by the way, Brian.
– Tanner Strunk
Jan 11 '18 at 17:33
1
@TannerStrunk: Yes, you're quite right, thanks! I'll add an edit.
– Brian Tung
Jan 11 '18 at 18:35
add a comment |
In addition to Brian Scott's excellent and clever answer, here's another, more straightforward way (in case you want to approach it with a geographical intuition): From two random variables $u_1, u_2$, distributed uniformly on the interval $[0, 1]$, generate (in radians) the latitude
$$
lambda = arccos (2u_1-1)-frac{pi}{2}
$$
and the longitude
$$
phi = 2pi u_2
$$
Then compute the rectangular coordinates accordingly:
$$
x = coslambdacosphi
$$
$$
y = coslambdasinphi
$$
$$
z = sinlambda
$$
ETA (thanks to Tanner Strunk—see comments): This will give coordinates of points on the unit sphere. To have them land on the sphere with diameter $20$ (and therefore radius $10$), simply multiply each by $10$.
This is the best way. Some points: 1. arccos(-1..1) normally gives the range 0..pi, so I would be inclined to subtract pi/2 instead of pi, to get a number in the range -pi/2 .. pi/2 which is how a geographer would present the angle. Actually I think this change is required, because the current answer will always give negative z. 2. Having done that, I see nothing wrong with z = 2u -1 and cos lamba = sqrt(1-z^2) 3. phi works just as well with 2*npiu2, which may be convenient in some computer implementations.
– Level River St
Dec 24 '15 at 11:06
Oops, I think you are right. Thanks for the look out.
– Brian Tung
Dec 24 '15 at 15:41
1
I'm a bit late in coming to this question (ha), but you should be scaling those x,y,z expressions by 10 to land on the sphere, right? (Tiny, nit-picky detail, but I figure it should be noted for future readers.) Nice avatar by the way, Brian.
– Tanner Strunk
Jan 11 '18 at 17:33
1
@TannerStrunk: Yes, you're quite right, thanks! I'll add an edit.
– Brian Tung
Jan 11 '18 at 18:35
add a comment |
In addition to Brian Scott's excellent and clever answer, here's another, more straightforward way (in case you want to approach it with a geographical intuition): From two random variables $u_1, u_2$, distributed uniformly on the interval $[0, 1]$, generate (in radians) the latitude
$$
lambda = arccos (2u_1-1)-frac{pi}{2}
$$
and the longitude
$$
phi = 2pi u_2
$$
Then compute the rectangular coordinates accordingly:
$$
x = coslambdacosphi
$$
$$
y = coslambdasinphi
$$
$$
z = sinlambda
$$
ETA (thanks to Tanner Strunk—see comments): This will give coordinates of points on the unit sphere. To have them land on the sphere with diameter $20$ (and therefore radius $10$), simply multiply each by $10$.
In addition to Brian Scott's excellent and clever answer, here's another, more straightforward way (in case you want to approach it with a geographical intuition): From two random variables $u_1, u_2$, distributed uniformly on the interval $[0, 1]$, generate (in radians) the latitude
$$
lambda = arccos (2u_1-1)-frac{pi}{2}
$$
and the longitude
$$
phi = 2pi u_2
$$
Then compute the rectangular coordinates accordingly:
$$
x = coslambdacosphi
$$
$$
y = coslambdasinphi
$$
$$
z = sinlambda
$$
ETA (thanks to Tanner Strunk—see comments): This will give coordinates of points on the unit sphere. To have them land on the sphere with diameter $20$ (and therefore radius $10$), simply multiply each by $10$.
edited Jan 11 '18 at 18:36
answered Dec 23 '15 at 0:14
Brian Tung
25.7k32553
25.7k32553
This is the best way. Some points: 1. arccos(-1..1) normally gives the range 0..pi, so I would be inclined to subtract pi/2 instead of pi, to get a number in the range -pi/2 .. pi/2 which is how a geographer would present the angle. Actually I think this change is required, because the current answer will always give negative z. 2. Having done that, I see nothing wrong with z = 2u -1 and cos lamba = sqrt(1-z^2) 3. phi works just as well with 2*npiu2, which may be convenient in some computer implementations.
– Level River St
Dec 24 '15 at 11:06
Oops, I think you are right. Thanks for the look out.
– Brian Tung
Dec 24 '15 at 15:41
1
I'm a bit late in coming to this question (ha), but you should be scaling those x,y,z expressions by 10 to land on the sphere, right? (Tiny, nit-picky detail, but I figure it should be noted for future readers.) Nice avatar by the way, Brian.
– Tanner Strunk
Jan 11 '18 at 17:33
1
@TannerStrunk: Yes, you're quite right, thanks! I'll add an edit.
– Brian Tung
Jan 11 '18 at 18:35
add a comment |
This is the best way. Some points: 1. arccos(-1..1) normally gives the range 0..pi, so I would be inclined to subtract pi/2 instead of pi, to get a number in the range -pi/2 .. pi/2 which is how a geographer would present the angle. Actually I think this change is required, because the current answer will always give negative z. 2. Having done that, I see nothing wrong with z = 2u -1 and cos lamba = sqrt(1-z^2) 3. phi works just as well with 2*npiu2, which may be convenient in some computer implementations.
– Level River St
Dec 24 '15 at 11:06
Oops, I think you are right. Thanks for the look out.
– Brian Tung
Dec 24 '15 at 15:41
1
I'm a bit late in coming to this question (ha), but you should be scaling those x,y,z expressions by 10 to land on the sphere, right? (Tiny, nit-picky detail, but I figure it should be noted for future readers.) Nice avatar by the way, Brian.
– Tanner Strunk
Jan 11 '18 at 17:33
1
@TannerStrunk: Yes, you're quite right, thanks! I'll add an edit.
– Brian Tung
Jan 11 '18 at 18:35
This is the best way. Some points: 1. arccos(-1..1) normally gives the range 0..pi, so I would be inclined to subtract pi/2 instead of pi, to get a number in the range -pi/2 .. pi/2 which is how a geographer would present the angle. Actually I think this change is required, because the current answer will always give negative z. 2. Having done that, I see nothing wrong with z = 2u -1 and cos lamba = sqrt(1-z^2) 3. phi works just as well with 2*npiu2, which may be convenient in some computer implementations.
– Level River St
Dec 24 '15 at 11:06
This is the best way. Some points: 1. arccos(-1..1) normally gives the range 0..pi, so I would be inclined to subtract pi/2 instead of pi, to get a number in the range -pi/2 .. pi/2 which is how a geographer would present the angle. Actually I think this change is required, because the current answer will always give negative z. 2. Having done that, I see nothing wrong with z = 2u -1 and cos lamba = sqrt(1-z^2) 3. phi works just as well with 2*npiu2, which may be convenient in some computer implementations.
– Level River St
Dec 24 '15 at 11:06
Oops, I think you are right. Thanks for the look out.
– Brian Tung
Dec 24 '15 at 15:41
Oops, I think you are right. Thanks for the look out.
– Brian Tung
Dec 24 '15 at 15:41
1
1
I'm a bit late in coming to this question (ha), but you should be scaling those x,y,z expressions by 10 to land on the sphere, right? (Tiny, nit-picky detail, but I figure it should be noted for future readers.) Nice avatar by the way, Brian.
– Tanner Strunk
Jan 11 '18 at 17:33
I'm a bit late in coming to this question (ha), but you should be scaling those x,y,z expressions by 10 to land on the sphere, right? (Tiny, nit-picky detail, but I figure it should be noted for future readers.) Nice avatar by the way, Brian.
– Tanner Strunk
Jan 11 '18 at 17:33
1
1
@TannerStrunk: Yes, you're quite right, thanks! I'll add an edit.
– Brian Tung
Jan 11 '18 at 18:35
@TannerStrunk: Yes, you're quite right, thanks! I'll add an edit.
– Brian Tung
Jan 11 '18 at 18:35
add a comment |
Same way as on a real sphere, but $(x,y,z) $ multiplied by $i.$
5
I'm afraid the OP by "imaginary" just meant "mathematical"
– leonbloy
Dec 22 '15 at 20:43
3
That's funny! ${}{}$
– copper.hat
Dec 22 '15 at 20:54
May have been edited on 23 March 2015 to remove "imaginary"
– Narasimham
Dec 23 '18 at 10:38
add a comment |
Same way as on a real sphere, but $(x,y,z) $ multiplied by $i.$
5
I'm afraid the OP by "imaginary" just meant "mathematical"
– leonbloy
Dec 22 '15 at 20:43
3
That's funny! ${}{}$
– copper.hat
Dec 22 '15 at 20:54
May have been edited on 23 March 2015 to remove "imaginary"
– Narasimham
Dec 23 '18 at 10:38
add a comment |
Same way as on a real sphere, but $(x,y,z) $ multiplied by $i.$
Same way as on a real sphere, but $(x,y,z) $ multiplied by $i.$
answered Dec 22 '15 at 20:35
Narasimham
20.5k52158
20.5k52158
5
I'm afraid the OP by "imaginary" just meant "mathematical"
– leonbloy
Dec 22 '15 at 20:43
3
That's funny! ${}{}$
– copper.hat
Dec 22 '15 at 20:54
May have been edited on 23 March 2015 to remove "imaginary"
– Narasimham
Dec 23 '18 at 10:38
add a comment |
5
I'm afraid the OP by "imaginary" just meant "mathematical"
– leonbloy
Dec 22 '15 at 20:43
3
That's funny! ${}{}$
– copper.hat
Dec 22 '15 at 20:54
May have been edited on 23 March 2015 to remove "imaginary"
– Narasimham
Dec 23 '18 at 10:38
5
5
I'm afraid the OP by "imaginary" just meant "mathematical"
– leonbloy
Dec 22 '15 at 20:43
I'm afraid the OP by "imaginary" just meant "mathematical"
– leonbloy
Dec 22 '15 at 20:43
3
3
That's funny! ${}{}$
– copper.hat
Dec 22 '15 at 20:54
That's funny! ${}{}$
– copper.hat
Dec 22 '15 at 20:54
May have been edited on 23 March 2015 to remove "imaginary"
– Narasimham
Dec 23 '18 at 10:38
May have been edited on 23 March 2015 to remove "imaginary"
– Narasimham
Dec 23 '18 at 10:38
add a comment |
Wolfram Mathworld provides a methodology for randomly picking a point on a sphere:
To obtain points such that any small area on the sphere is expected to contain the same number of points, choose $u$ and $ν$ to be random variates on $[0,1]$. Then: $$begin{array}{ll}theta=2pi u\
varphi= arccos(2v - 1)end{array}$$ gives the spherical coordinates for a set of points which are uniformly distributed over $mathbb{S}^2$.
1
Except for the link, this seems to be exactly the same as Brian Tung's earlier answer.
– Ilmari Karonen
Dec 23 '15 at 18:39
add a comment |
Wolfram Mathworld provides a methodology for randomly picking a point on a sphere:
To obtain points such that any small area on the sphere is expected to contain the same number of points, choose $u$ and $ν$ to be random variates on $[0,1]$. Then: $$begin{array}{ll}theta=2pi u\
varphi= arccos(2v - 1)end{array}$$ gives the spherical coordinates for a set of points which are uniformly distributed over $mathbb{S}^2$.
1
Except for the link, this seems to be exactly the same as Brian Tung's earlier answer.
– Ilmari Karonen
Dec 23 '15 at 18:39
add a comment |
Wolfram Mathworld provides a methodology for randomly picking a point on a sphere:
To obtain points such that any small area on the sphere is expected to contain the same number of points, choose $u$ and $ν$ to be random variates on $[0,1]$. Then: $$begin{array}{ll}theta=2pi u\
varphi= arccos(2v - 1)end{array}$$ gives the spherical coordinates for a set of points which are uniformly distributed over $mathbb{S}^2$.
Wolfram Mathworld provides a methodology for randomly picking a point on a sphere:
To obtain points such that any small area on the sphere is expected to contain the same number of points, choose $u$ and $ν$ to be random variates on $[0,1]$. Then: $$begin{array}{ll}theta=2pi u\
varphi= arccos(2v - 1)end{array}$$ gives the spherical coordinates for a set of points which are uniformly distributed over $mathbb{S}^2$.
edited Dec 24 '15 at 13:05
Daniel Fischer♦
173k16160282
173k16160282
answered Dec 23 '15 at 12:06
varunk
1192
1192
1
Except for the link, this seems to be exactly the same as Brian Tung's earlier answer.
– Ilmari Karonen
Dec 23 '15 at 18:39
add a comment |
1
Except for the link, this seems to be exactly the same as Brian Tung's earlier answer.
– Ilmari Karonen
Dec 23 '15 at 18:39
1
1
Except for the link, this seems to be exactly the same as Brian Tung's earlier answer.
– Ilmari Karonen
Dec 23 '15 at 18:39
Except for the link, this seems to be exactly the same as Brian Tung's earlier answer.
– Ilmari Karonen
Dec 23 '15 at 18:39
add a comment |
Thanks for contributing an answer to Mathematics Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f1585975%2fhow-to-generate-random-points-on-a-sphere%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
Simply Pythagorean theorem?
– MonkeyKing
Dec 22 '15 at 20:31
4
do you want the points to be uniformly random on the surface of the sphere?
– Alex R.
Dec 22 '15 at 20:33
8
Possible duplicate of Picking random points in the volume of sphere with uniform probability
– leonbloy
Dec 22 '15 at 20:42
7
@leonbloy: Not a duplicate, since that one was for the solid sphere.
– Brian M. Scott
Dec 22 '15 at 22:39
4
This is the correct duplicate: How can I pick a random point on the surface of a sphere with equal distribution? But the answers here are better (although they are mostly covered by the MathWorld article I linked above).
– Rahul
Dec 23 '15 at 1:04