球体内的随机数? [英] Random numbers within a sphere?

查看:77
本文介绍了球体内的随机数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我想知道是否有人可以帮我解决我在C ++中遇到的问题。我想要选择球体积内的随机点。我知道如何使用srand()和rand()来获取随机数,但不知道如何在更复杂的几何体中执行
。任何帮助都会非常感激。


问候

Stavros

Hello everyone,

I was wondering if someone could help me with an issue I have in C++. I
want to select random points within the volume of a sphere. I know how
to get random numbers using srand() and rand(), but have no idea how to
do that within a more complicated geometry. Any help would be greatly
appreciated..

Regards
Stavros

推荐答案

Stavros Christoforou写道:
Stavros Christoforou wrote:
大家好,

我想知道是否有人可以帮我解决我遇到的问题C ++。我想要选择球体积内的随机点。我知道如何使用srand()和rand()获取随机数,但不知道如何在更复杂的几何体中执行此操作。任何帮助都会非常受欢迎..
Hello everyone,

I was wondering if someone could help me with an issue I have in C++. I
want to select random points within the volume of a sphere. I know how
to get random numbers using srand() and rand(), but have no idea how to
do that within a more complicated geometry. Any help would be greatly
appreciated..




您可以用球坐标表示球体的任何点:a

半径和两个角度。坐标是一个统一变量(使用rand())

其[min,max]间隔。



You could represent any point of the sphere in spherical coordinates: a
radius and two angles. A coordinate is a uniform variable (using rand()) in
its [min,max] interval.


Stavros Christoforou写道:
Stavros Christoforou wrote:
我想知道是否有人可以帮我解决我在C ++中遇到的问题。我想要选择球体积内的随机点。我知道如何使用srand()和rand()获取随机数,但不知道如何在更复杂的几何体中执行此操作。任何帮助都会得到很大的赞赏..
I was wondering if someone could help me with an issue I have in C++. I
want to select random points within the volume of a sphere. I know how
to get random numbers using srand() and rand(), but have no idea how to
do that within a more complicated geometry. Any help would be greatly
appreciated..




选择一个随机半径(在0和球体半径之间),一个randon方位角

(0到2 * Pi)和随机高程(-Pi / 2到Pi / 2)然后

将三个值从球坐标转换为笛卡尔坐标(如果

表示你想要的结果。请不要在这里发表题外话题

。你的问题与C ++语言无关,应该在comp.graphics.algorithms或comp.programming中发布




V



Select a random radius (between 0 and the sphere radius), a randon azimuth
(0 through 2*Pi) and a random elevation (-Pi/2 through Pi/2) and then
convert the three values from spherical coordinates into Cartesian (if
that''s your desired result). And please don''t post off-topic questions
here. Your question has nothing to do with C++ language and ought to be
posted in comp.graphics.algorithms or comp.programming.

V


Fabio Rossi写道:
Fabio Rossi wrote:
Stavros Christoforou写道:
Stavros Christoforou wrote:
大家好,

我想知道是否有人可以帮我解决我在C ++中遇到的问题。我想要选择球体积内的随机点。我知道如何使用srand()和rand()获取随机数,但不知道如何在更复杂的几何体中执行此操作。任何帮助都会非常受欢迎。
您可以用球坐标表示球体的任何点:半径和两个角度。坐标是一个统一变量(使用rand())
Hello everyone,

I was wondering if someone could help me with an issue I have in C++. I
want to select random points within the volume of a sphere. I know how
to get random numbers using srand() and rand(), but have no idea how to
do that within a more complicated geometry. Any help would be greatly
appreciated..
You could represent any point of the sphere in spherical coordinates: a
radius and two angles. A coordinate is a uniform variable (using rand())



的[最小,最大]间隔。


in its [min,max] interval.




Stavros可能需要均匀分布的数字。一个极坐标方案

至少会在中心附近聚集数字。


修复方法是用一个立方体绑定球体,在所有面上相切通过找到随机的xyz点,每个> = -r和<来找到立方体中随机点的

r,

其中r是球体的半径。然后将x ^ 2 + y ^ 2 + z ^ 2与r ^ 2进行比较,过滤掉球体外部所有点b / b



-

Phlip
http:/ /industrialxp.org/community/bi...UserInterfaces



Stavros might need evenly distributed numbers. A polar coordinate scheme
would bunch numbers up around the center, at least.

The fix is to bound the sphere with a cube, tangent on all faces, and find
random points in the cube by finding random xyz points, each >= -r and < r,
where r is the radius of the sphere. Then filter out all points laying
outside the sphere, by comparing x^2 + y^2 + z^2 to r^2.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces


这篇关于球体内的随机数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆