Making a sphere out of points

Hi,

So I’ve been exploring different methods of making the verts of a sphere, I’ve got a really simple method that creates a 2d circle of points, then spins it round by an amount of circles / 180, basically making a terry’s chocolate orange, or for anyone without a reference an inflatable beach ball. This isn’t the most ideal method for this task as I end up with overlapping verts at the poles. So I either create a list and search through for identical verts or figure out a better way to make a sphere.

I’ve seen a few different methods around, one being the Icososphere and the dart throwing one, I’d like to ideally make an algorithm that distributes points evenly across a sphere, as with my current method there’s always the same bunching of circles, as the radius gets smaller on the sphere towards the poles there are still the same amount of points as the band in the middle.

Does anyone know any better way to make spheres? All methods welcome!

The Terry’s chocolate orange script:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class SphereSimpleWorking3 : MonoBehaviour
{
    public GameObject cubes;

    private GameObject[] objects = null;
    public int numberOfObjectsinPool = 20;

    public int numberOfObjects = 20; // Number of objects around circle
    public int numberOfCircles = 3; // How many rotations around a sphere

    public float radius = 5f; // Radius of main circle
    public Transform parent;
    private int currentRes;
    private int increment;

    private float sphereAngle = 0f;
    private Vector3 currentPoint;
    public GameObject target;

    public List <Vector3> vertList = new List<Vector3> ();

    void Start()
    {
        objects = new GameObject[numberOfObjectsinPool];
        int increment = 0;

        for (int i = 0; i < numberOfObjectsinPool; i++) // Start up main objects
        {
            objects[i] = Instantiate (cubes) as GameObject;
            objects[i].transform.parent = parent.transform;
            objects[i].SetActive (false);
        }
    }

    void Update()
    {
        if (currentRes != numberOfObjects * numberOfCircles)
        {
            ClearObjs ();
            vertList.Clear ();
            increment = 0;

            StartCoroutine("StartMakingSphere");
        }
    }

    void ClearObjs()
    {
        for (int i = 0; i < numberOfObjectsinPool; i++)
        {
            objects[i].SetActive(false);
        }
    }

    IEnumerator StartMakingSphere()
    {
        currentRes = numberOfObjects * numberOfCircles;

        for (int j = 0; j < numberOfCircles; j++)
        {
            for (int i = 0; i < numberOfObjects; i++)
            {
                float angle = (i * Mathf.PI * 2 / numberOfObjects);
                float x = Mathf.Cos (angle) * radius;
                float y = Mathf.Sin (angle) * radius;
                Vector3 pos = new Vector3 (0, x, y);
                ActivateObj(pos, i);
                //    vertList.Add(pos); // This is adding the same position to the list as it's always made in same place in world and then it'srotated.
                transform.parent = gameObject.transform;
                yield return new WaitForSeconds (0.1f);
            }
            yield return new WaitForSeconds (0.1f);
            sphereAngle = 180 / numberOfCircles;
            transform.RotateAround(Vector3.zero, Vector3.up, sphereAngle);
        }

        yield return null;
        //    SearchList();
    }

    void ActivateObj(Vector3 pos, int i)
    {

        //        objects[increment].name = i + "" + j;
        objects[increment].transform.position = pos;
        objects[increment].SetActive(true);
        vertList.Add(pos);
        increment++;
        if (increment > (numberOfObjectsinPool))
        {
            increment = 0;
        }
    }

    void SearchList()
    {
        Debug.Log ("i'm doing the Calculations for you now...");
        for (int i = 0; i < vertList.Count; i++)
        {
            if (vertList[i] == Vector3.zero) // How do I search through the list to find if there is an overlapping vert?
            {                                 // Or should I dismiss the poles by half of objects in circle, first and middle taken out after first loop around
                Debug.Log("Same");
            }
        }
    }
}

I think I thought of another way of doing it, draw a line from 0,1 on one axis ie Y, these are the poles.
Split line into sections to make rings, the radius of the rings is what I can’t work out, outside of a sphere is like half a wave going up, so could use a 1/2 a wave function to work out the radius for the rings or something.

How ever I’m unsure of how to much change or whether to increase/decrease the amount of verts as you go up the sphere, this might not be the best way to make an even spacing of points on a sphere, totally unsure.

Some interesting articles by CatLikeCoding :

WHAWHAWHAT!! I love Jasper’s tuts can’t believe I have over looked these gems, damn my silly little head. And thank you very very very very much!!