%% BEGIN pst-chladni.tex
%%
%% plotting chladni example images
%%
%% COPYRIGHT 2026 Jürgen Gilg (+ 2024)
%%                Manuel Luque
%%                Herbert Voss, hvoss@tug.org.
%%
%% This program can be redistributed and/or modified under the terms
%% of the LaTeX Project Public License Distributed from CTAN
%% archives in directory macros/latex/base/lppl.txt.
%%
%%
\csname PSTChladniLoaded\endcsname
\let\PSTChladniLoaded\endinput

\ifx\PSTricksLoaded\endinput       \else\input pstricks.tex\fi
\ifx\PSTSOLIDESIIIDLoaded\endinput \else\input pst-solides3d \fi
\ifx\PSTXKeyLoaded\endinput        \else\input pst-xkey \fi
%
\def\fileversion{0.01}
\def\filedate{2026/06/12}
\message{ v\fileversion, \filedate}
%
\edef\TheAtCode{\the\catcode`\@}
\catcode`\@=11

\pstheader{pst-chladni-Bessel.pro}
\pst@addfams{pst-chladni}
\define@key[psset]{pst-chladni}{n}{\def\psk@chladni@n{#1 }} % n
\define@key[psset]{pst-chladni}{m}{\def\psk@chladni@m{#1 }} % m
\define@key[psset]{pst-chladni}{R}{\def\psk@chladni@R{#1 }} % R
\psset[pst-chladni]{n=1,m=1,R=1}
%
\def\psNodalLinesCircularPlane{\pst@object{psNodalLinesCircularPlane}}
\def\psNodalLinesCircularPlane@i{%
  \begin@SpecialObj
  \addto@pscode{
    40 dict begin
  	%tx@BesselDict begin
	/nMode \psk@chladni@n def
	/mMode \psk@chladni@m def
	/Rayon \psk@chladni@R def
	/Point 0.0352778 def
	/Point2  {Point 2 div} bind def
	/Point4  {Point 4 div} bind def
	/Pixel {xP CM 0.25 sub yP CM 0.25 sub moveto
        xP CM 0.5 add yP CM 0.25 sub lineto
        xP CM 0.5 add yP CM 0.5 add lineto
        xP CM 0.25 sub yP CM 0.5 add lineto
    } def
	/CM {28.4527559067 mul} def
	/PI 3.14159265359 def
	/Div { dup 0 eq { pop } { div } ifelse } def
	/RadtoDeg {180 mul PI div} bind def
	/ALPHA { tx@BesselDict begin BesselJZeros end nMode get mMode 1 sub get} bind def
	/date 0 def
	/uXYT {nMode ALPHA xP dup mul yP dup mul add sqrt mul tx@BesselDict begin BesselJ end
       ALPHA date mul RadtoDeg cos mul yP xP atan nMode mul cos mul
  	} def
	gsave
	newpath
	0 0 Rayon CM 0 360 arc
	closepath
	clip
	Point2 Point4 Rayon {/rP exch def % on parcourt toute la surface de la membrane
 	/stepAngle Point4 rP div PI div 180 mul def
	0 stepAngle 90  {/Angle exch def
      /xP rP Angle cos mul def
      /yP rP Angle sin mul def
      % uXYT abs 0.01 le {/HUEcolor 0 def}{/HUEcolor uXYT abs def} ifelse
      % HUEcolor 1 1 sethsbcolor
      uXYT abs 0.025 le {/GRAY 0 def}{/GRAY 1 def} ifelse
	  GRAY setgray
 	  newpath
 	  Pixel
 	  closepath
 	  fill
 	  /xP xP neg def
  	  newpath
 	  Pixel
 	  closepath
 	  fill
  	  /yP yP neg def
      newpath
 	  Pixel
 	  closepath
 	  fill
  	  /xP xP neg def
  	  newpath
 	  Pixel
 	  closepath
 	  fill
 	} for
  }for
  0 setgray
  stroke
  grestore
  newpath
  0 0 Rayon CM 0 360 arc
  closepath
  %0 0 1 setrgbcolor
  0 setgray
  0 setgray
  end % dict
  }%
  \end@OpenObj
}
\pst@addfams{pst-circularmembrane}
\define@key[psset]{pst-circularmembrane}{date}{\def\pst@date{#1 }} % rayon de la membrane
\define@key[psset]{pst-circularmembrane}{n}{\def\pst@modeN{#1 }} % n
\define@key[psset]{pst-circularmembrane}{m}{\def\pst@modeM{#1 }} % m
\define@key[psset]{pst-circularmembrane}{coeffZ}{\def\pst@coeffZ{#1 }} % réduction de z
%
\psset[pst-circularmembrane]{date=0,n=0,m=1,coeffZ=1}
%
\def\psCircularMembrane{\@ifnextchar[\psCircularMembrane@i{\psCircularMembrane@i[]}}
\def\psCircularMembrane@i[#1]{%
  \begingroup
  \psset{ngrid=0.1 0.1,solidmemory,linewidth=0.2pt,#1}%
  \pstVerb{
 	/nMode \pst@modeN def
 	/mMode \pst@modeM def
 	/date \pst@date def
 	/coeffZ \pst@coeffZ def
 	/ALPHA {tx@BesselDict begin BesselJZeros end nMode get mMode 1 sub get} bind def 
  }%
  \psPolygonIIID[linecolor=red,fillcolor=gray!50,fillstyle=solid](-1,-1,0)(-1,1,0)(1,1,0)(1,-1,0)%
  \psSolid[object=plan,definition=equation,args={[0 0 1 0]},name=monplan,action=none]%
  %% affectation du plan de projection
  \psset{plan=monplan}%
  \psProjection[object=cercle,args=0 0 1,linecolor=blue,linewidth=2\pslinewidth,range=0 360]%
  \composeSolid
  \psSurface*[incolor=white,linewidth=0.1pt,
    r=1,intersectionplan={[0 0 1 0]},intersectioncolor=(bleu),intersectionlinewidth=1,
    intersectiontype=0,axesboxed, showAxes=false,Zmin=-1,Zmax=1](-1,-1)(1,1){%
      nMode ALPHA x dup mul y dup mul add sqrt mul 
      tx@BesselDict begin BesselJ end ALPHA date mul RadtoDeg cos 
      mul y x atan nMode mul cos mul coeffZ mul}%
  \psLineIIID[linecolor=red](1,-1,0)(1,1,0)(-1,1,0)%
  \endgroup
  \ignorespaces
}
\def\psNodalCircular(#1,#2){%
    \begin{pspicture}(-1,-1)(1,1)
    \psNodalLinesCircularPlane[n=#1,m=#2]
    \end{pspicture}}
\catcode`\@=\TheAtCode\relax

\endinput
