0

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.

1
  • 3
    Moving a vector from origin 0 to some other point like the center of the screen is what a translation does. Commented Dec 30, 2012 at 15:47

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.