File:Rotating spherical harmonics.gif

From WikiEducator
Jump to: navigation, search
Rotating_spherical_harmonics.gif(445 × 445 pixels, file size: 799 KB, MIME type: image/gif, looped, 21 frames)

This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.

Description
English: Rotating spherical harmonics, to 4 vertical, to ±4 horizontal
Deutsch: Veranschaulichung einiger Kugelflächenfunktionen (um die z-Achse rotierend). Dargestellt ist , wobei l der Zeile und m der Spalte entspricht. Zeilen und Spalten werden jeweils bei null beginnend durchnummeriert
Source Own work
Author Cyp
Permission
(Reusing this file)
GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License.
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
This licensing tag was added to this file as part of the GFDL licensing update.

Source in C:

//GPL (as if anyone would want this anyway...)
#include <stdio.h>
#include <math.h>

#define PI 3.14159265358979323846264338327950288

//m>=0
double cfac(int l, int m, double z) {
  int x;
  int i;
  double r, s, t;
  r=log((2*l+1)*(.25/PI))*.5;
  r-=log(2)*l;
  i=(l+m+1)>>1;
  for(x=2;x<=l-i;++x) r-=   log(x);
 if(l-m<i) {
/*for(   ;x<=l-m;++x) r+= 0*log(x);*/ x=l-m+1;
  for(   ;x<=i  ;++x) r-=.5*log(x);
 } else {
/*for(   ;x<=i  ;++x) r-= 0*log(x);*/ x=i+1;
  for(   ;x<=l-m;++x) r+=   log(x);
 }
  for(   ;x<=l+m;++x) r+=.5*log(x);
  for(   ;x<=2*i;++x) r+=   log(x);

  if(m) r+=.5*log(2);

  r=exp(r)*((l^i)&1?-1:1)*(2*i-l-m?z:1);
  s=-z*z;
  t=r;
  for(i=((l+m+1)>>1)+1;i<=l;++i) t+=r*=s*(2*i-1)*(2*i)*(l-i+1)/((double)(2*i-l-m-1)*(2*i-l-m)*i);
  return(t);
}

double cval(int m, double x, double y) {
  int i;
  _Complex double d=x+1i*y, r;
  for(r=1;m;m>>=1,d*=d) if(m&1) r*=d;
  return(__real__ r);
}

void rend(unsigned char *c, int sx, int sy, int pit, int l, int m, double ang) {
  int a, b;
  double x, y, z, sa, ca, f, t, r;
  sa=sin(ang); ca=cos(ang);
  for(b=0;b<sy;++b) {
    for(a=0;a<sx;++a) {
    z=1-b*2/(sy-1.);
      x=a*2/(sx-1.)-1;
      t=1-x*x-z*z;
      if(t<0) t=1e99; else {
        y=-sqrt(t);
        t=cos(.2)*z-sin(.2)*y;
        y=sin(.2)*z+cos(.2)*y;
        z=t;
        t=ca*x+sa*y;
        y=-sa*x+ca*y;
        x=t;
    f=cfac(l, m, z);
        t=cval(m, x, y)*f;//printf("a%lf, %lf, %lf, %lf\n", t, x, y, z);
      }
      r=128+t*512; if(r<0) r=0; else if(r>255) r=255; c[a*3+b*pit  ]=(int)r|31;
      r=128+t*256; if(r<0) r=0; else if(r>255) r=255; c[a*3+b*pit+1]=(int)r|15;
      r=128+t*128; if(r<0) r=0; else if(r>255) r=255; c[a*3+b*pit+2]=(int)r|7;
    }
  }
}

unsigned char pic[256*256*3];

int main(void) {
  FILE *f;
  char fn[100];
  int a, l, m;
  for(a=0;a<256*256*3;++a) pic[a]=255;
  for(a=0;a<100;++a) {
    for(l=0;l<=4;++l) for(m=0;m<=l;++m) rend(pic+m*27*3+l*27*134*3, 26, 26, 134*3, l, m, PI*2/100*a);
//    for(l=0;l<=4;++l) for(m=0;m<=l;++m) rend(pic+m*51*3+l*51*256*3, 50, 50, 256*3, l, m, PI*2/100*a);
//    rend(pic+4*51*3+0*51*256*3, 50, 50, 256*3, 47, 1, PI*2/100*a);
//    rend(pic+4*51*3+0*51*256*3, 50, 50, 256*3, 47, 11, PI*2/100*a);
//    rend(pic, 256, 256, 256*3, 5, 2, PI*2/100*a);
    sprintf(fn, "sph%04d.ppm", a);
    f=fopen(fn, "wb");
    fprintf(f, "P6\n%d %d\n255\n", 134, 134);
    fwrite(pic, 134*134*3, 1, f);
    fclose(f);
  }
/*  int l, m, i;
  double r;
  for(l=0;l<=7;++l) for(m=0;m<=l;++m) {
    printf("%d,%d: %lf", l, m, r=cfac(l, m));
    for(i=((l+m+1)>>1)+1;i<=l;++i) printf(", %lf", r*=(double)(2*i-1)*(2*i)*(l-i+1)/((double)(2*i-l-m-1)*(2*i-l-m)*i));
    printf("\n");
  }*/
  return(0);
}

Source in Mathematica:

Export["Rotating spherical harmonics.gif",
 Table[
  GraphicsGrid[
   Table[
    SphericalPlot3D[
     1,
     {\[Theta], 0, \[Pi]},
     {\[CapitalPhi], 0, 2 \[Pi]},
     ColorFunction -> Function[
       {x, y, z, \[Theta], \[Phi], r},
       Blend[
        {RGBColor["#1F2F57"], RGBColor["#FFCFA7"]},
        2*(Re[
            SphericalHarmonicY[l, m, \[Theta], \[Phi]]*
             Exp[- Sign[m] I t]] + 0.25)]],
     ColorFunctionScaling -> False,
     Mesh -> False,
     Boxed -> False,
     Axes -> False,
     PlotPoints -> 10,
     MaxRecursion -> 2,
     ViewPoint -> Front,
     ImageSize -> {80, 80}
     ],
    {l, 0, 5},
    {m, 0, l}
    ]
   ],
  {t, 0, 2 \[Pi], \[Pi]/10}
  ]
 ]

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

image/gif

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current00:06, 4 December 2016Thumbnail for version as of 00:06, 4 December 2016445 × 445 (799 KB)ChemmixChanged range to ℓ = 0, …, 4 as in original file.

The following page links to this file: