Here's the code. I have indicated the \j1 and \j2 lines with long arrows on the right.
Code: Select all
\documentclass[tikz]{standalone}
\usepackage{fp}
\usetikzlibrary{math, fixedpointarithmetic}
\begin{document}
\begin{tikzpicture}[fixed point arithmetic]
% Variables
% j1, m1, j2, m2: Input spin vectors
% jtot, mtot: Input total spin vector
% jitot, mitot, mi1, mi2: Temporary spin vector values for the coeff function
% blocks: Number of coefficient boxes
% dw, dh: Number of cells per per box
% aoldx, aoldy: Coordinates of the top right of the last coeefficient grid
% anewx, anewy: Coordinates of the top right of the new coefficient grid
% num: Number to be converted to fraction
% r: Returned fraction
% w, h: Width and height of one cell
% n, d: Throw-away integers
% c, i, j, k, hm1, p, q, s, wjtot: Throw-away variables
% Program Block
\tikzmath {
% Convert A Decimal To A Fraction
function f(\num) {
integer \n, \d;
\stop=0;
for \k in {1,...,200} {
\a=\k*\num;
if \stop==0 then {
if int(abs(\a))==abs(\a) then {
if \k==1 then {\n=\num; let \r="\n"; \stop=1; }
else {\n=\a; \d=\k; let \r="\n/\d"; \stop=1; };
};
};
};
return \r;
};
function coeff(\jitot,\mitot,\mi1,\mi2) {
\j1=1/2; \j2=1/2; %<--------------------------------------------------------------------
\s=0;
for \ki in {0,...,0} {
\s=\s+1/((\ki)!*(\j1+\j2-\jitot-\ki)!*(\j1-\mi1-\ki)!*(\j2+\mi2-\ki)!*(\jitot-\j2+\mi1+\ki)!*(\jitot-\j1-\mi2+\ki)!);
};
\c=sqrt((2*\jitot+1)*(\jitot+\j1-\j2)!*(\jitot-\j1+\j2)!*(\j1+\j2-\jitot)!/(\j1+\j2+\jitot+1)!);
\c=\c*sqrt((\jitot+\mitot)!*(\jitot-\mitot)!*(\j1-\mi1)!*(\j1+\mi1)!*(\j2-\mi2)!*(\j2+\mi2)!);
\c=\c*\s;
return \c;
};
\w=1.2; \h=0.6;
\j1=1/2; \j2=1/2; %<-------------------------------------------------------------------------
\m1=\j1; \m2=\j2;
\jtot=\j1+\j2; \mtot=\jtot;
\blocks=2*(\j1+\j2)+1;
% Spins
\aoldx=0; \aoldy=0;
\p=f(\j1); \q=f(\j2); {\node at ({\aoldx-\w},{\aoldy+\h/2}) {\p + \q}; };
for \i in {1,...,\blocks} {
% J Block Settings
\wjtot=\jtot; \c=0; \stop=0;
for \x in {0,...,2*\jtot} {
if \stop==0 then {
if \wjtot>=\mtot then {\c=\c+1; };
if \wjtot<=-\mtot then {\stop=1; };
\wjtot=\wjtot-1;
};
};
\dw=\c;
% m1, m2 Block Settings
\hm1=\m1; \c=0;
for \x in {0,...,2*\m1} {
if -\m2>\mtot-(\m1-\x) then {\hm1=\hm1-1; };
if \m2<\mtot-(\m1-\x) then {\c=\c+1; };
};
\dh=(2*\m1+1)-(\m1-\hm1)-\c;
if \i==1 then {\dw=1; \dh=1; \hm1=\m1; };
if \i==\blocks then {\dw=1; \dh=1; \hm1=-\m1; };
% Boxes and Spin States
\anewx=\aoldx+\dw*\w; \anewy=\aoldy-\dh*\h;
{\draw (\aoldx,\aoldy) rectangle (\anewx,\anewy); };
{\draw[line width=2pt] (\aoldx,\aoldy) -- ++ ({-2*\w},0) -- ++(0,-\dh*\h) -- ++ ({2*\w+\dw*\w},0) -- ++(0,{2*\h+\dh*\h}) -- ++(-\dw*\w,0) -- cycle; };
for \j in {0,...,\dw-1} {
for \k in {0,...,\dh-1} {
\p=f(\jtot-\j); \q=f(\mtot); {\node at ({\aoldx+\w/2+\j*\w},{\aoldy+3*\h/2}) {\p}; \node at ({\aoldx+\w/2+\j*\w},{\aoldy+\h/2}) {\q}; };
\p=f(\hm1-\k); \q=f(\mtot-(\hm1-\k)); {\node at ({\aoldx-3*\w/2},{\aoldy-\h/2-\k*\h}) {\p}; \node at ({\aoldx-\w/2},{\aoldy-\h/2-\k*\h}) {\q}; };
\p=coeff(\jtot-\j,\mtot,\hm1-\k,\mtot-(\hm1-\k));
\q=f(round(100*(\p)^2)/100); { \node at ({\aoldx+\w/2+\j*\w},{\aoldy-\h/2-\k*\h}) {\q}; };
};
};
\mtot=\mtot-1;
\aoldx=\anewx; \aoldy=\anewy;
};
};
\end{tikzpicture}
\end{document}
-Dan