I am trying to generate vectors equidistant from a point at the centre of the screen.
Previously, I was following the below approach
1. Generate random numbers Random(0-400, 0+400) for x, y and z
2. Normalize the vectors
3. Scale them to whatever distance wanted
However, this was when my origin was at 0. Now, that I have to do something like this from the centre of the screen. I tried to go with the following approach, and this for some reason is giving me x and y only in the positive quadrant (z comes out to be fine)
//Origin (midpointX of screen, midPointY of screen, z=0)
//vector<Vec3f> positions;
//positions.push_back(getPoint().scale(300);
getPoint{
Vec3f rVector;
rVector.set( Random(midPointX-100,midPointX+100), Random(midPointY-100,midPointY+100), Random(0-100,0+100) );
}
Assume all these points on lie on the sirface of a sphere of some radius. Hence, these are equidistant from the centre(x,y,z). It would be great to know of a better approach to generate these points.
I am fine with the algorithm only.
Do you care about the pdf (probability dristribution) of the angles? By generating uniformly-distributed random points in a cube, you will tend to favor the directions of the cube’s corners. This is obviously different from sampling random points on the surface of a sphere.
If you want a uniform distribution on the surface of a sphere, try e.g. Sphere Point Picking (basically, generate angles independently, instead of x-y-z coordinates)
As far as moving the sphere from the origin to a different point, that is just a matter of adding constants to your end result (x-y-z coordinates computed from polar coordinates), as others have pointed out.