How would I make a sphere with equidistant vertices?

I’m trying to make a spherical burst of rays for the purpose of checking collision, but having specific interactions happen based upon what on where each ray hit. Hence why I’m using rays rather then something simpler such as OverlapSphere. But that doesn’t really matter so much. The reason I’m looking for how to make a sphere is because I can use the same math for my rays, by having them go to the vertices of where the sphere would be. But every way I can find for making a sphere has the lines get closer the near to the poles, which makes sense, as its pretty easy to do. But as you can imagine, its not that useful for my current project.

TL;DR:
How do I make a sphere with equidistant vertices? If its not perfectly equidistant its fine, it just needs to pretty close. If this happens, it would be great if you could give how much the difference would be, and where, if applicable.

Extra notes:
I’ve looked at this and this, but the math is way over my head, so what I’ve been looking for might’ve just been staring me in the face this whole time.

Hey Matrixmage

Packing is definitely overkill for this, and I too have trouble reading mathematical proofs.

The following has been my approach in the past:

  1. Determine the distance between each vert (in your case, the angle between each ray).

  2. Determine the circumference of the sphere = 2 * PI * radius (in your case, 360.0f)

  3. Now we can calculate the number of verts we want to have in one sweep. We only want the verts going down one side of the sphere for now:

alt text

int halfCircumferenceVertCount = Mathf.Floor((circumference / 2.0f) / distanceBetweenVerts);
  1. Don’t forget the bottom cap

alt text

halfCircumferenceVertCount += 1;
  1. Now we are going to loop over our vert count and do pretty much the same steps again, but for each horizontal slice:

alt text

// We don't need to bother with the top or bottom cap here
for (int index=1; index < halfCircumferenceVertCount - 1; index++)
  1. Now this is the hardest part. We need to calculate the circumference of each slice:

alt text

6.1) First we need the angle from the equator:

float angleFromTop = (index / halfCircumferenceVertCount) * 180.0f;
float angleFromEquator = 0.0f;

if (angleFromTop <= 90.0f)
    angleFromEquator = 90.0f - angleFromTop;
else
    angleFromEquator = angleFromTop - 90.0f;

6.2) Now we do some trig to get the circumference of the slice at that angle:

float sliceCircumference = 2 * PI * radius * Mathf.Cos(Mathf.deg2rad * angleFromEquator);
  1. Now we can calculate how many verts are on this slice:

    int sliceCircumferenceVertCount = Mathf.Floor(sliceCircumference / distanceBetweenVerts);

  2. We loop through these verts:

    for (int sliceIndex=0; sliceIndex < sliceCircumferenceVertCount; sliceIndex++)
    {
    float angleFromHalfCircumference =
    (sliceIndex / sliceCircumferenceVertCount) * 360.0f;

     Quaternion pitch = Quaternion.Euler(-angleFromTop, 0.0f, 0.0f);
     Quaternion yaw = Quaternion.Euler(0.0f, angleFromHalfCircumference, 0.0f);
    
     Quaternion lookAtVert = yaw * pitch;
     Vector3 forward = Vector3.up * lookAtVert;
    
     Physics.Raycast(transform.position, forward, 10.0f);
    

    }

  3. Don’t forget to do your raycast for directly up and directly down!

I’ve written this from memory so there may be some mistakes, but it shouldn’t be too hard to figure out where I went wrong. Also I tend to get quaternion multiplication the wrong way around, so that may be wrong.

Thanks,
Ves