#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# face objects outwards in a uniform angle

edited October 2015

hello there, i'm sure there is an easy answer to this...

i'm rotating ellipses around a circle, but each ellipse seems to face the same direction...

but i want them all to face uniformly around the sphere...

i've tried a bunch of stuff... nothing seems to work without throwing things into chaos.

i imagine its something like... divide the amount of objects by their angle around the sphere, rotating each by that much... but i just can't get it...

i've commented out the rotation line where I think i should, but uncomment and you'll see what i mean... the ellipse kind've rotate in a non-uniform fashion...

what i'm trying to do is have every ellipse angle at the right angle to the centre of the sphere... if that makes sense... like rays of sunshine or something... or if i had a piece of string going out to each ellipse, the ellipse rotates on the angle of that piece of string...

hope someone can help...

``````int radius = 150;
float d = 0.0;
void setup() {
size(1000, 1000, P3D);
noStroke();
}

void draw() {
background(0);
translate(width/2, height/2);
lights();
sphereDetail(50);
stroke(100, 100, 255);
sphere(100);
for (int deg = 0; deg < 360; deg += 10) {
float x = (cos(angle) * radius);
float z = (sin(angle) * radius);
pushMatrix();
translate(x, z, 0);
fill(50, 200, 255);
pushMatrix();
//rotateY(90);
ellipse(0, 0, 20, 20);
popMatrix();
popMatrix();
}
}
``````
Tagged:

• I can get what I want the normal old way, just rotating within a for loop...

But the particular sketch I'm working on needs the sin/cos/translate code as used above...

``````int radius = 150;
float d = 0.0;
float theta = 0;
void setup() {
size(400, 400, P3D);
noStroke();
}

void draw() {
background(0);
translate(width/2, height/2);
lights();

for (int i = 0; i < 360; i+=45) {

stroke(255);
pushMatrix();
ellipse(0, -100, 100, 100);
popMatrix();
}
}
``````
• You're close. Really close. The second example sketch really helped. Have a solution.

``````int radius = 150;
float d = 0.0;
void setup() {
size(1000, 1000, P3D);
noStroke();
}

void draw() {
background(0);
translate(width/2, height/2);
lights();
sphereDetail(50);
stroke(100, 100, 255);
sphere(100);
for (int deg = 0; deg < 360; deg += 10) {
float x = (cos(angle) * radius);
float z = (sin(angle) * radius);
pushMatrix();
translate(x, z, 0);
fill(50, 200, 255);
pushMatrix();
rotateY(HALF_PI);
rotateX(HALF_PI-angle);
ellipse(0, 0, 20, 20);
popMatrix();
popMatrix();
}
}
``````

This was a good forum post. You posted formatted sample code and everything. Please stay and be an example for others!

• hmmmm..... i appear to have fixed it... for now... mind you i have no idea what i'm doing... trial and error for 3 hours is the only way I know how to fix things :(

``````int radius = 150;
float d = 0.0;
float theta = 0;
void setup() {
size(400, 400, P3D);
noStroke();
fill(50, 200, 255);
}

void draw() {
background(0);
translate(width/2, height/2);
lights();
sphereDetail(50);
sphere(20);

for (int deg = 0; deg < 360; deg += 45) {

pushMatrix();

float x = (cos(angle) * radius);
float z = (sin(angle) * radius);

translate(x, 0, z);