Skip to content

Random unit vector optimization #941

Discussion options

You must be logged in to vote

If you use the vec3::random(double,double) function, you're essentially generating random points in the cube with vertices at (-1,-1,-1) and (+1,+1,+1). However, the diameter from the center of one side to the opposite side is smaller than the diameter from one corner to the opposite corner. In fact, it's ≅ 1.7 times (√3) longer, so more points are generated along this diameter than along the center-to-center diameter.

On normalization, these points are "squished" (projected) to the point on the surface of the embedded sphere. As a result, you get an uneven distribution of points on the surface of this sphere.

In contrast, the rejection method presented in the book ensures that only point…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by CincyAndroiDeveloper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants