I’ve been trying to generate a 3D object based on the superformula for some time, and came to the realization I needed something to help wrap meshes around a series of points. I am able to generate a series of 3D points no problem, but I need to create a 3D object out of those points, so I’ve been playing with the ofxDelaunay addon to help with that.
In my code, I add about 100 points to the Delaunay object, then try to run .triangulate() on it. However, every time the program hits that call to triangulate, the program freezes and sometimes throws a segmentation fault.
My code is quite simple, so I’ll post it here:
#include “testApp.h”
//--------------------------------------------------------------
void testApp::setup(){
// Generate the supershape
a = 1;
b = 1;
m1 = 5;
m2 = 3;
n1_1 = 1;
n2_1 = 2;
n3_1 = 1;
n1_2 = 1;
n2_2 = 5;
n3_2 = 3;
xres = 10;
yres = 10;
scaleFactor = 100;
// Delaunay
buildSupershape();
}
//--------------------------------------------------------------
void testApp::update(){
ofBackground(0);
}
//--------------------------------------------------------------
void testApp::draw(){
}
// Actual superformula implementation
float testApp::superformula(float a, float b, float m, float n1, float n2, float n3, float angle) {
float r;
float t1,t2;
t1 = cos(m * angle / 4) / a;
t1 = abs(t1);
t1 = pow(t1, n2);
t2 = sin(m * angle / 4) / b;
t2 = abs(t2);
t2 = pow(t2, n3);
r = pow(t1+t2, 1/n1);
return r;
}
// Calculations a 3D supershape point based on polar coordinates
ofPoint testApp::calculatePoint(float theta, float phi) {
// Run superformula for given values
float r1 = superformula(a, b, m1, n1_1, n2_1, n3_1, theta);
float r2 = superformula(a, b, m2, n1_2, n2_2, n3_2, phi);
// Calculate coordinates
float x = r1 * cos(theta) * r2 * cos(phi);
float y = r1 * sin(theta) * r2 * cos(phi);
float z = r2 * sin(phi);
// Return the resulting vector
return ofPoint(x*scaleFactor, y*scaleFactor, z*scaleFactor);
}
void testApp::buildSupershape() {
// Reset the Delaunay points
delaunay.reset();
// Determine resolution of shape
int thetaStep = 360 / xres;
int phiStep = 180 / yres;
// Generate each point
int index = 1;
for (float i = -180; i < 180; i += thetaStep) {
for (float j = -90; j < 90; j += phiStep) {
ofPoint p = calculatePoint(i, j);
float zz = delaunay.addPoint§;
cout << p.z << “\n”;
index++;
}
}
delaunay.triangulate();
delaunay.draw();
}
As I say, the call to delaunay.triangulate seems to be the issue. I haven’t found any documentation for this addon, but have seen a few people use it, so I was hoping someone could provide some insight Let me know if I can provide anything else!