Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been working on creating spheres in a 3D space recently, and have successfully created cylinders. I've just run into a little problem. For some reason, my "Spheres" end up looking like very thick star shapes. I can't seem to figure out what's wrong, and I could not really find any algorithms to reference off of. My code:

public static void createCircle(int xoff, int yoff, int zoff, int FOV, ArrayList<Point3D> Points, int radius) {
    for(int j=0;j<Math.PI*2;j++) {
        int x = (int) (radius * Math.cos(j));
        int y = (int) (radius * Math.sin(j));
        Points.add(new Point3D(x+xoff, y+yoff, zoff, FOV, 900, 600));
public static void createSphere(int radius, int height, int FOV, ArrayList<Point3D> Points, int posx, int posy, int posz) {
    for(int z=0;z<height;z++) {
        createCircle(posx, posy, posz+z, FOV, Points, (int) (radius*(Math.sin(z)*2)));

Here's what it ends up looking like: Error

share|improve this question
It would be helpful if you could post an image of what they currently look like. Additionally, there's a similar question here which may help you. And my answer there has code very similar to yours here that you can reference. – Byte56 Jan 16 '13 at 17:54
up vote 3 down vote accepted

You are using integers for all your numbers, unless you have a very specific purpose and know what you are doing, stick to floats for geometry.

Your radius calculation is completely wrong, in createSphere you should do something like:

for(float angle=0;angle<Math.PI;angle+=0.1){
    createCircle(posx, posy, posz + Math.cos(angle)*height/2, FOV, Points,
share|improve this answer
Thank you, I'm rather new to 3D so this really helped a lot. – Dylan Katz Jan 16 '13 at 20:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.