The reason why the triangle is arranged in a spherical shape

Hello, I’m studying 3D with Mastering openFrameworks.

I was looking at the example, and I was wondering why the triangle was placed in a circle.

void ofApp::setup(){
	ofBackground(0);
	ofEnableDepthTest();

	nTri = 1500;
	nVert = nTri * 3;

	float Rad = 250;
	float rad = 25;

	vert.resize(nVert);
	for (int i = 0; i < nTri; i++)
	{
		ofPoint center(ofRandom(-1, 1), ofRandom(-1, 1), ofRandom(-1, 1));
		center.normalize();
		center *= Rad;

		for (int j = 0; j < 3; j++)
		{
			vert[i * 3 + j] = center + ofPoint(ofRandom(-rad, rad),
				ofRandom(-rad, rad),
				ofRandom(-rad, rad));

		}
	}
	colors.resize(nTri);
	for (int i = 0; i < nTri; i++)
	{
		colors[i] = ofColor(ofRandom(0, 255), 0, 0);
	}
}
void ofApp::draw(){
	ofEnableDepthTest();
	ofBackgroundGradient(ofColor(255), ofColor(128));
	ofPushMatrix();
	ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2, 0);

	float time = ofGetElapsedTimef();
	float angle = time * 10;

	ofRotate(angle, 0, 1, 0);

	for (int i = 0; i < nTri; i++)
	{
		ofSetColor(colors[i]);
		ofTriangle(vert[i * 3], vert[i * 3 + 1], vert[i * 3 + 2]);
	}
	ofPopMatrix();
}

Why ? Just an esthetic / design choice.

How ? this lines :

		ofPoint center(ofRandom(-1, 1), ofRandom(-1, 1), ofRandom(-1, 1));
		center.normalize();
		center *= Rad;

Which sample a 3d unit cube (1st line), normalize the point to get a unit sphere (2nd line), and multiply by a radius value to change its size (3rd line).

Note that this method will give you a non uniform sampling distribution of the sphere, but it get the job done pretty easily.