Debian Codegraph @

examples/math/spherical-harmonics.ck

raw
1 // name: spherical-harmonics.ck
2 // desc: explanation of Math.sh()
3 // author: everett m. carpenter
4 // date: spring 2026
5
6 // three arguments must be given to Math.sh()
7 3 => int order; // analogous to block size in the FFT, this determines how many projections upon bases we are calculating
8 23.0 => float azimuth; // horizontal angle in degrees (counter clockwise is positive)
9 0.0 => float elevation; // vertical angle in degrees (positive is upwards, 90 is north pole, negative downwards, 0 is the equator)
10
11 // Math.sh() will return an array of size (order+1)^2
12 Math.sh(order, azimuth, elevation) @=> float projections[];
13
14 for(int acn; acn < projections.size(); acn++)
15 {
16 // due to Math.sh() being writting with ambisonics in mind, projections are returned in Ambisonic Channel Order (ACN)
17 chout <= "ACN: " <= acn;
18 // but the order and degree of a projection are calculable from ACN
19 Math.floor(Math.sqrt(acn)) $ int => int order;
20 acn - order * order - order => int degree;
21
22 // print
23 chout <= " Order: " <= order <= " Degree: " <= degree <= " Value: " <= projections[acn] <= IO.nl();
24 }