Forums > Jitter

spherical harmonics

June 14, 2006 | 8:50 am

dear friends of spheres and cubes!

has anyone taken a look at the spherical harmonics at:

http://astronomy.swin.edu.au/~pbourke/surfaces/sphericalh/

has anyone written an expression for this "simple formula"?

i constantly fuck up. my state of mind visible at

http://www.fuckhead.at/didi/pix.html

cheers!


June 15, 2006 | 1:10 am

On Jun 14, 2006, at 1:50 AM, didi bruckmayr wrote:

>
> has anyone taken a look at the spherical harmonics at:
> http://astronomy.swin.edu.au/~pbourke/surfaces/sphericalh/
> has anyone written an expression for this "simple formula"?

XYZ Eval(double theta,double phi, int *m)
{
double r = 0;
XYZ p;

r += pow(sin(m[0]*phi),(double)m[1]);
r += pow(cos(m[2]*phi),(double)m[3]);
r += pow(sin(m[4]*theta),(double)m[5]);
r += pow(cos(m[6]*theta),(double)m[7]);

p.x = r * sin(phi) * cos(theta);
p.y = r * cos(phi);
p.z = r * sin(phi) * sin(theta);

return(p);
}

is probably easiest to accomplish with two cascaded expressions. One
to compute radius, r, and then passed to a second one to convert to
xyz based on r, theta, and phi.

In the above, replace m[N] with in[N] (to create adjustable
parameters); replace theta with norm[0]*TWOPI, and phi with norm[1]
*PI (to convert our normalized X and Y axis values to normalized
radian based coordinates across the surface of the sphere), and that
should be it.

So the expression for r would be:

"pow(in[0]*PI*norm[1],in[1]) + pow(cos(in[2]*PI*norm[1]),in[3]) +
pow(sin(in[4]*TWOPI*norm[0]),in[5]) + pow(cos(in[6]*TWOPI*norm[0]),
[7])"

then your output expressions for xyz would be the following (where
theta and phi are replaced by the same, and r is replaced by in[0]).
You could do with a single instance of jit.expr by replacing r with
the first expression above, but it will be more expensive to compute
for each x, y, and z rather than once for all, as I’ve suggested.

"in[0]*sin(PI*norm[1])*cos(TWOPI*norm[0])"
"in[0]*cos(PI*norm[1])"
"in[0]*sin(PI*norm[1])*sin(TWOPI*norm[0])"

Quick hack example below. There’s some stupid problem with updating
the float values and jit.expr, which requires banging the input
again, which I’ll look into (might be some bug for jit.expr float
input), but this should give a decent example of how to convert such
stuff into jit.expr expressions.

-Joshua

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 103 175 50 196617 deferlow;
#P newex 109 127 40 196617 t b b l;
#P newex 238 575 261 196617 jit.gl.shader foo @name shady @file
vz.normals.mdl.jxs;
#P newex 39 348 94 196617 jit.matrix @thru 0;
#P newex 49 543 48 196617 r render;
#N vpreset 8;
#X append 1 1 50 178 713 flonum float 1. ; 49 178 637 flonum float
4. ; 48 178 561 flonum float 1. ; 47 178 485 flonum float 2. ; 46
178 409 flonum float 1. ; 45 178 333 flonum float;
#X append 1 1 8. ; 44 178 257 flonum float 1. ; 43 178 181 flonum
float 2. ;;
#X append 2 1 50 178 713 flonum float 1. ; 49 178 637 flonum float
1. ; 48 178 561 flonum float 23. ; 47 178 485 flonum float 3.11 ;
46 178 409 flonum float 16. ; 45 178 333 flonum float;
#X append 2 1 5. ; 44 178 257 flonum float 0.11 ; 43 178 181 flonum
float 0.81 ;;
#X append 3 1 50 178 713 flonum float 1. ; 49 178 637 flonum float
2. ; 48 178 561 flonum float 12. ; 47 178 485 flonum float 1. ; 46
178 409 flonum float 1. ; 45 178 333 flonum float;
#X append 3 1 6. ; 44 178 257 flonum float 1. ; 43 178 181 flonum
float 3. ;;
#X append 4 1 50 178 713 flonum float 1. ; 49 178 637 flonum float
3.01 ; 48 178 561 flonum float 1. ; 47 178 485 flonum float -6. ;
46 178 409 flonum float 1. ; 45 178 333 flonum float;
#X append 4 1 24. ; 44 178 257 flonum float 1. ; 43 178 181 flonum
float 1. ;;
#X append 5 1 50 178 713 flonum float 1. ; 49 178 637 flonum float
4. ; 48 178 561 flonum float 1. ; 47 178 485 flonum float 2. ; 46
178 409 flonum float 1. ; 45 178 333 flonum float;
#X append 5 1 1. ; 44 178 257 flonum float 9. ; 43 178 181 flonum
float 3. ;;
#X append 8 1 50 178 713 flonum float 1. ; 49 178 637 flonum float
1. ; 48 178 561 flonum float 1. ; 47 178 485 flonum float -3. ; 46
178 409 flonum float 1. ; 45 178 333 flonum float;
#X append 8 1 24. ; 44 178 257 flonum float 1. ; 43 178 181 flonum
float 1. ;;
#P preset 370 60 47 27;
#P hidden button 217 112 15 0;
#P comment 650 301 100 196617 calculate xyz;
#P comment 736 251 100 196617 calculate r;
#P flonum 713 178 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 637 178 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 561 178 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 485 178 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 409 178 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 333 178 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 257 178 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 181 178 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 181 216 130 196617 jit.matrix 1 float32 64 64;
#P window linecount 2;
#P newex 182 292 377 196617 jit.expr 3 float32 64 64 @expr "in[0]*sin
(PI*norm[1])*cos(TWOPI*norm[0])" "in[0]*cos(PI*norm[1])" "in[0]*sin
(PI*norm[1])*sin(TWOPI*norm[0])";
#P newex 181 247 545 196617 jit.expr 1 float32 64 64 @inputs 8 @expr
"pow(sin(in[0]*PI*norm[1])\,in[1]) + pow(cos(in[2]*PI*norm[1])\,
in[3]) + pow(sin(in[4]*TWOPI*norm[0])\,in[5]) + pow(cos(in[6]
*TWOPI*norm[0])\,in[7])";
#P window linecount 1;
#P newex 31 515 230 196617 jit.gl.handle foo @inherit_transform 1
@radius 2;
#P toggle 332 351 15 0;
#P comment 353 351 100 196617 draw as mesh;
#P hidden message 48 413 68 196617 camera 0 0 4;
#P flonum 753 332 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 715 332 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 675 332 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 650 359 85 196617 pak scale 1. 1. 1.;
#P toggle 168 452 15 0;
#P newex 129 451 35 196617 sel 27;
#P message 168 470 68 196617 fullscreen $1;
#P newex 86 494 186 196617 jit.window foo @depthbuffer 1 @fsaa 1;
#P newex 84 451 40 196617 key;
#P number 109 103 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 139 150 54 196617 dim $1 $1;
#P newex 272 446 48 196617 s render;
#P flonum 772 380 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 734 380 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 694 380 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P toggle 459 384 15 0;
#P message 459 407 94 196617 smooth_shading $1;
#P message 185 410 79 196617 color 0. 1. 0. 1.;
#P toggle 558 384 15 0;
#P message 558 407 90 196617 lighting_enable $1;
#P toggle 136 389 15 0;
#P message 136 410 44 196617 axes $1;
#P toggle 352 388 15 0;
#P toggle 311 387 15 0;
#P newex 270 408 92 196617 pak poly_mode 0 0;
#P hidden newex 498 341 50 196617 loadbang;
#P number 60 105 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P toggle 371 384 15 0;
#P message 371 407 81 196617 depth_enable $1;
#P toggle 15 105 15 0;
#P newex 15 131 57 196617 qmetro 20;
#P newex 15 185 58 196617 t b b erase;
#P newex 15 585 152 196617 jit.gl.render foo @shader shady;
#P hidden message 499 363 14 196617 1;
#P newex 666 404 95 196617 pak position 0. 0. 0.;
#P window linecount 2;
#P comment 190 82 100 196617 m[0]-m[7] coefficients;
#P connect 6 0 5 0;
#P connect 5 0 4 0;
#P hidden fasten 36 0 3 0 53 506 20 506;
#P fasten 4 0 3 0 20 393 20 393;
#P fasten 4 2 3 0 68 273 20 273;
#P fasten 39 0 3 0 36 558 20 558;
#P connect 55 0 3 0;
#P fasten 56 0 3 0 44 396 20 396;
#P connect 4 1 56 0;
#P fasten 41 0 56 0 187 334 44 334;
#P hidden connect 10 0 36 0;
#P connect 9 0 5 1;
#P fasten 29 0 28 0 173 489 91 489;
#P connect 58 0 59 0;
#P connect 26 0 58 0;
#P fasten 27 0 30 0 89 470 126 470 126 449 134 449;
#P connect 15 0 14 0;
#P connect 58 2 25 0;
#P fasten 30 0 31 0 134 469 165 469 165 449 173 449;
#P connect 31 0 29 0;
#P hidden connect 54 0 43 0;
#P hidden connect 53 0 43 0;
#P connect 59 0 42 0;
#P connect 25 0 42 0;
#P connect 43 0 42 0;
#P connect 42 0 40 0;
#P connect 25 0 40 0;
#P connect 25 0 41 0;
#P connect 40 0 41 0;
#P hidden connect 58 1 53 0;
#P hidden connect 54 0 44 0;
#P hidden connect 53 0 44 0;
#P connect 44 0 40 1;
#P fasten 1 0 24 0 671 426 277 426;
#P fasten 14 0 24 0 141 428 277 428;
#P fasten 16 0 24 0 563 426 277 426;
#P fasten 19 0 24 0 464 426 277 426;
#P fasten 18 0 24 0 190 428 277 428;
#P fasten 11 0 24 0 275 428 277 428;
#P fasten 7 0 24 0 376 426 277 426;
#P fasten 32 0 24 0 655 426 277 426;
#P fasten 38 0 12 0 337 376 316 376;
#P connect 12 0 11 1;
#P hidden connect 54 0 45 0;
#P hidden connect 53 0 45 0;
#P connect 45 0 40 2;
#P fasten 38 0 13 0 337 377 357 377;
#P connect 13 0 11 2;
#P hidden fasten 2 0 8 0 504 381 376 381;
#P connect 8 0 7 0;
#P hidden connect 54 0 46 0;
#P hidden connect 53 0 46 0;
#P connect 46 0 40 3;
#P hidden fasten 2 0 20 0 504 381 464 381;
#P connect 20 0 19 0;
#P hidden connect 54 0 47 0;
#P hidden connect 53 0 47 0;
#P connect 47 0 40 4;
#P hidden connect 10 0 2 0;
#P hidden fasten 2 0 17 0 504 381 563 381;
#P connect 17 0 16 0;
#P hidden connect 54 0 48 0;
#P hidden connect 53 0 48 0;
#P connect 48 0 40 5;
#P hidden connect 54 0 49 0;
#P hidden connect 53 0 49 0;
#P connect 49 0 40 6;
#P connect 33 0 32 1;
#P connect 21 0 1 1;
#P fasten 34 0 32 2 720 353 705 353;
#P hidden connect 54 0 50 0;
#P hidden connect 53 0 50 0;
#P connect 50 0 40 7;
#P fasten 22 0 1 2 739 399 727 399;
#P fasten 35 0 32 3 758 353 730 353;
#P fasten 23 0 1 3 777 399 755 399;
#P window clipboard copycount 60;


Viewing 2 posts - 1 through 2 (of 2 total)