Rendering spherical harmonics

   1305   0   0
User Avatar
Member
1 posts
Joined: March 2022
Offline
Hi all, my coding skills are abysmal but I've made an attempt at trying to generate spherical harmonics with what I thought was a straight forward formula.

Would someone be so kind as to let me know what I've done wrong in my script? I was expecting a beautiful spherical harmonic, and instead was given a cube ?

The formula I am trying to implement is:

r = sin(a * φ)^b + cos(c * φ)^d + sin(e * θ)^f + cos(g * θ)^h
The script I created is:

int iteration = chi("../Controller/iteration");

int A = chi("../Controller/A");
int B = chi("../Controller/B");
int C = chi("../Controller/C");
int D = chi("../Controller/D");
int E = chi("../Controller/E");
int F = chi("../Controller/F");
int G = chi("../Controller/G");
int H = chi("../Controller/H");

vector c = @P;
vector v = @P;

for(int i=0; i<iteration; i++){
    float r = length(v);
    float phi = atan2(v.y, v.x);
    float theta = atan2(sqrt(v.x * v.x + v.y*v.y), v.z);
    
    float vx = sin(pow(A * phi, B)) + cos(pow(C * phi, D)) + sin(pow(E * theta, F)) + cos(pow(G * theta, H));
    float vy = sin(pow(A * phi, B)) + cos(pow(C * phi, D)) + sin(pow(E * theta, F)) + cos(pow(G * theta, H));
    float vz = sin(pow(A * phi, B)) + cos(pow(C * phi, D)) + sin(pow(E * theta, F)) + cos(pow(G * theta, H));
    
    v = set(vx, vy, vz) + c;
    
    if(length(v) > 100){
        @density = 0;
    }
}
  • Quick Links