%% scale_length.ldf
%% Created by Laurence D. Finston (LDF) Fri 08 Jul 2022 06:39:54 AM CEST

%% * (1) Copyright and License.

%%%% Copyright (C) 2022 Laurence Finston

%%%% You can redistribute this file and/or modify 
%%%% it under the terms of the GNU General Public License as published by 
%%%% the Free Software Foundation; either version 3 of the License, or 
%%%% (at your option) any later version.  

%%%% This file is distributed in the hope that it will be useful, 
%%%% but WITHOUT ANY WARRANTY; without even the implied warranty of 
%%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
%%%% GNU General Public License for more details.  

%%%% You should have received a copy of the GNU General Public License 
%%%% along with this file; if not, write to the Free Software 
%%%% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 

%%%% The author can be contacted at: 

%%%% Laurence Finston 
%%%% Laurence.Finston@gmx.de


%% * (1) Top

verbatim_metapost "prologues := 3;\noutputtemplate := \"%j%3c.eps\";";

input "plainldf.lmc";

pickup pencircle scaled (.333mm, .333mm, .333mm);

numeric wd;
numeric n[];

picture v[];

beginfig(1);

  point p[];

  numeric r;
  r := 1.0595;

  point a[];

  a0 := (1cm, 0);  

  j := 24;
  
  for i = 0 upto 24:
    % message "i == " & decimal i;
    % message "j == " & decimal j;
    if i > 0:
      a[i] := r*a[i-1] shifted a0;
    fi;
    p[j] := (-xpart a[i], ypart a[i]);
    if j < 13:
      dotlabel.bot("$p_{" & decimal j & "}$", p[j]) shifted (0, -.5cm);
    fi
    j -= 1;
  endfor;
  %pause;
  
  dotlabel.bot("$p_0$", p0) shifted (0, -.5cm);
  
  dotlabel.bot("C", p0) shifted (0, -1.5cm);
  dotlabel.bot("C\#", p1) shifted (0, -1.5cm);
  dotlabel.bot("D", p2) shifted (0, -1.5cm);
  dotlabel.bot("D\#", p3) shifted (0, -1.5cm);
  dotlabel.bot("E", p4) shifted (0, -1.5cm);
  dotlabel.bot("F", p5) shifted (0, -1.5cm);
  dotlabel.bot("F\#", p6) shifted (0, -1.5cm);
  dotlabel.bot("G", p7) shifted (0, -1.5cm);
  dotlabel.bot("G\#", p8) shifted (0, -1.5cm);
  dotlabel.bot("A", p9) shifted (0, -1.5cm);
  dotlabel.bot("A\#", p10) shifted (0, -1.5cm);
  dotlabel.bot("B", p11) shifted (0, -1.5cm);
  dotlabel.bot("C", p12) shifted (0, -1.5cm);

  pickup pencircle scaled (.333mm, .333mm, .333mm);
  
  drawarrow p0 -- (p24 shifted (2cm, 0)) with_color dark_gray;
  
  p30 := p0 shifted (0, 6cm);

  dotlabel.lft("$p_{30}$", p30);
  
  draw p0 -- p30;

  p31 := p24 shifted (0, 2cm);

  dotlabel.llft("$p_{31}$", p31);

  draw p24 -- p31;

  p32 := (xpart p0, ypart p31);

  dotlabel.lft("$p_{32}$", p32);

  drawarrow p32 -- (p31 shifted (2cm, 0)) with_color dark_gray;

  draw p30 -- p31 with_pen pencircle scaled (.5mm, .5mm, .5mm);

  dotlabel.bot("$p_{24}$", p24) shifted (0, -.5cm);
  
  p33 := p1 shifted (0, 5cm);
  dotlabel.lrt("$p_{33}$", p33);
  draw p1 -- p33;
  draw p30 -- p33 -- p31 with_color red;

  p34 := p4 shifted (0, 4cm);
  dotlabel.lrt("$p_{34}$", p34) shifted (0, -2pt);
  draw p4 -- p34;
  draw p30 -- p34 -- p31 with_color blue;

  p35 := p7 shifted (0, 3cm);
  dotlabel.llft("$p_{35}$", p35);
  draw p7 -- p35;
  draw p30 -- p35 -- p31 with_color dark_green;


  p36 := p12 shifted (0, 2.333cm);
  dotlabel.llft("$p_{36}$", p36) shifted (0, -.5cm);
  draw p36 -- p36 shifted (-.333cm, -.575cm)
    with_pen pencircle scaled (.25mm, .25mm, .25mm);
  draw p12 -- p36;
  draw p30 -- p36 -- p31 with_color purple;

  p37 := (p7, p35) intersection_point (p30, p31);
  %dotlabel.llft("$p_{37}$", p37);

  p38 := (p7, p35) intersection_point (p32, p31);
  %dotlabel.ulft("$p_{38}$", p38);

  p39 := (p1, p33) intersection_point (p32, p31);
  dotlabel.llft("$p_{39}$", p39);

  p40 := (p1, p33) intersection_point (p30, p31);
  dotlabel.ulft("$p_{40}$", p40);
  
  v0 := current_picture;
  scale v0 (.667, .667);

  for i = 13 upto 24:
    dotlabel.bot("$p_{" & decimal i & "}$", p[i]) shifted (0, -.5cm);
  endfor;
  
  dotlabel.bot("C\#", p13) shifted (0, -1.5cm);
  dotlabel.bot("D", p14) shifted (0, -1.5cm);
  dotlabel.bot("D\#", p15) shifted (0, -1.5cm);
  dotlabel.bot("E", p16) shifted (0, -1.5cm);
  dotlabel.bot("F", p17) shifted (0, -1.5cm);
  dotlabel.bot("F\#", p18) shifted (0, -1.5cm);
  dotlabel.bot("G", p19) shifted (0, -1.5cm);
  dotlabel.bot("G\#", p20) shifted (0, -1.5cm);
  dotlabel.bot("A", p21) shifted (0, -1.5cm);
  dotlabel.bot("A\#", p22) shifted (0, -1.5cm);
  dotlabel.bot("B", p23) shifted (0, -1.5cm);
  dotlabel.bot("C", p24) shifted (0, -1.5cm);


  n0 := magnitude(p31 - p30);
  label.top("$n_0=\overline{\vbox to 1.5ex{\vss}p_{30}p_{31}}=" & decimal n0 & "$",
      p37) shifted (0, .25cm);

  n1 := magnitude(p32 - p31);
  label.llft("$n_1=" & decimal n1 & "$", p38) shifted (0, -.125cm);

  label("\setbox0=\hbox{$n_0-n_1$}\vbox{\hbox{$n_0-n_1 = " & decimal (n0 - n1) & "$}"
      & "\hbox{\hbox to \wd0{$n_0/n_1$\hss} $= " & decimal (n0 / n1) & "$}}",
      p37 shifted (4cm, 2cm));
  
  n6 := magnitude(p40 - p31);
  label.urt("$n_6=\overline{\vbox to 1.5ex{\vss}p_{40}p_{31}}=" & decimal n6 & "$",
      p40) shifted (0, .25cm);

  p41 := mediate(p30, p33);
  %dotlabel.lft("$p_{41}$", p41);

  n7 := magnitude(p30 - p33);

  label.bot("$n_7=" & decimal n7 & "$", p41) shifted (-10pt, -.25cm) with_color red;
  
  p42 := mediate(p33, p34);
  %dotlabel.lft("$p_{42}$", p42);

  n8 := magnitude(p33 - p31);
  label.bot("$n_8=\overline{\vbox to 1.5ex{\vss}p_{33}p_{31}}=" & decimal n8 & "$",
      p42) shifted (0, -2pt) with_color red;

  n9 := magnitude(p39 - p31);
 
  label.top("$n_9=\overline{\vbox to 1.5ex{}p_{39}p_{31}}=" & decimal n9 & "$",
      p39 shifted (4cm, 0));

  p43 := p42 shifted (.5cm, 4.5cm);
  %dotlabel.lft("$p_{43}$", p43);

  label.rt("\setbox0=\hbox{$n_6-n_8$ }"
      & "\vbox{\hbox{$n_6-n_8=" & decimal (n6 - n8) & "$}"
      & "\hbox{$n_6-n_9=" & decimal (n6 - n9) & "$}"
      & "\hbox{$n_8-n_9=" & decimal (n8 - n9) & "$}"
      & "\hbox{\hbox to \wd0{$n_6/n_8$\hfil}"
      & "$=" & decimal (n6 / n8) & "$}"
      & "\hbox{\hbox to \wd0{$n_6/n_9$\hfil}"
      & "$=" & decimal (n6 / n9) & "$}"
      & "\hbox{\hbox to \wd0{$n_8/n_9$\hfil}"
      & "$=" & decimal (n8 / n9) & "$}"
      & "}", p43);


%pause;
  
  v10 := current_picture;
  scale v10 (.667, .667);
  
  current_picture := v10;

endfig with_projection parallel_x_y;

beginfig(2);
  v1 := v0;
  scale v1 (.667, 1);
  output v1 with_projection parallel_x_y;
  for i = 13 upto 24:
    drawdot p[i] with_pen pencircle scaled (1mm, 1mm, 1mm);
  endfor;
  n2 := .667 * magnitude(p31 - p30);
  label.top("$n_2=" & decimal n2 & "$", p37) shifted (0, .25cm);
  n3 := .667 * magnitude(p31 - p32);
  label.llft("$n_3=" & decimal n3 & "$", p38) shifted (0, -.125cm);

  label("\setbox0=\hbox{$n_2-n_3$}\vbox{\hbox{$n_2-n_3 = " & decimal (n2 - n3) & "$}"
      & "\hbox{\hbox to \wd0{$n_2/n_3$\hss} $= " & decimal (n2 / n3) & "$}}",
      p37 shifted (7cm, 2cm));

  n10 := .667 * magnitude(p40 - p31);   %% n6 
  n11 := .667 * magnitude(p30 - p33);   %% n7
  n12 := .667 * magnitude(p33 - p31);   %% n8
  n13 := .667 * magnitude(p39 - p31);   %% n9


  label.urt("$n_{10}=\overline{\vbox to 1.5ex{\vss}p_{40}p_{31}}=" & decimal n10 & "$",
      p40) shifted (0, .25cm);

  label.bot("$\scriptstyle n_{11}=" & decimal n11 & "$", p41)
    shifted (0, -.5cm) with_color red;

  label.bot("$n_{12}=\overline{\vbox to 1.5ex{\vss}p_{33}p_{31}}=" & decimal n12 & "$",
      p42) shifted (0, -.25cm) with_color red;

  label.top("$n_{13}=\overline{\vbox to 1.5ex{}p_{39}p_{31}}=" & decimal n13 & "$",
      p39 shifted (5cm, 0));
    
  label.rt("\setbox0=\hbox{$n_{10}-n_{12}$ }"
      & "\vbox{\hbox{$n_{10}-n_{12}=" & decimal (n10 - n12) & "$}"
      & "\hbox{$n_{10}-n_{13}=" & decimal (n10 - n13) & "$}"
      & "\hbox{$n_{12}-n_{13}=" & decimal (n12 - n13) & "$}"
      & "\hbox{\hbox to \wd0{$n_{10}/n_{12}$\hfil}"
      & "$=" & decimal (n10 / n12) & "$}"
      & "\hbox{\hbox to \wd0{$n_{10}/n_{13}$\hfil}"
      & "$=" & decimal (n10 / n13) & "$}"
      & "\hbox{\hbox to \wd0{$n_{12}/n_{13}$\hfil}"
      & "$=" & decimal (n12 / n13) & "$}"
      & "}", p43 shifted (3cm, 0));
  
  scale current_picture (.667, .667);
  scale current_picture (.667, 1);

endfig with_projection parallel_x_y;

beginfig(3);
  v2 := v0;
  scale v2 (.375, 1);
  output v2 with_projection parallel_x_y;
  for i = 13 upto 24:
    drawdot p[i] with_pen pencircle scaled (1mm, 1mm, 1mm);
  endfor;

  n4 := .375 * magnitude(p31 - p30);
  label.top("$n_4=" & decimal n4 & "$", p37) shifted (0, .25cm);
  n5 := .375 * magnitude(p31 - p32);
  label.llft("$n_5=" & decimal n5 & "$", p38) shifted (0, -.125cm);

  label("\setbox0=\hbox{$n_4-n_5$}\vbox{\hbox{$n_4-n_5 = " & decimal (n4 - n5) & "$}"
      & "\hbox{\hbox to \wd0{$n_4/n_5$\hss} $= " & decimal (n4 / n5) & "$}}",
      p37 shifted (13cm, 2cm));

  n14 := .375 * magnitude(p40 - p31);   %% n6 
  n15 := .375 * magnitude(p30 - p33);   %% n7
  n16 := .375 * magnitude(p33 - p31);   %% n8
  n17 := .375 * magnitude(p39 - p31);   %% n9

  label.urt("$n_{14}=\overline{\vbox to 1.5ex{\vss}p_{40}p_{31}}=" & decimal n14 & "$",
      p40) shifted (0, .25cm);

  label.bot("$n_{15}=\overline{\vbox to 1.5ex{}p_{30}p_{33}}=" & decimal n15 & "$", p30)
    shifted (0, 3cm) with_color red;

  label.bot("$n_{16}=\overline{\vbox to 1.5ex{\vss}p_{33}p_{31}}=" & decimal n16 & "$",
      p30) shifted (0, 2cm) with_color red;

  label.top("$n_{17}=\overline{\vbox to 1.5ex{}p_{39}p_{31}}=" & decimal n17 & "$",
      p39 shifted (5cm, 0));
    
  label.rt("\setbox0=\hbox{$n_{14}-n_{16}$ }"
      & "\vbox{\hbox{$n_{14}-n_{16}=" & decimal (n14 - n16) & "$}"
      & "\hbox{$n_{14}-n_{17}=" & decimal (n14 - n17) & "$}"
      & "\hbox{$n_{16}-n_{17}=" & decimal (n16 - n17) & "$}"
      & "\hbox{\hbox to \wd0{$n_{14}/n_{16}$\hfil}"
      & "$=" & decimal (n14 / n16) & "$}"
      & "\hbox{\hbox to \wd0{$n_{14}/n_{17}$\hfil}"
      & "$=" & decimal (n14 / n17) & "$}"
      & "\hbox{\hbox to \wd0{$n_{16}/n_{17}$\hfil}"
      & "$=" & decimal (n16 / n13) & "$}"
      & "}", p43 shifted (3cm, 0));





  scale current_picture (.667, .667);
  scale current_picture (.375, 1);
endfig with_projection parallel_x_y;

end_mp;
end;
  
%% ** (2) End of 3DLDF code.

%% * (1) Emacs-Lisp code for use in indirect buffers when using the          
%%       GNU Emacs editor.  The local variable list is not evaluated when an 
%%       indirect buffer is visited, so it's necessary to evaluate the       
%%       following s-expression in order to use the facilities normally      
%%       accessed via the local variables list.                              
%%       \initials{LDF 2004.02.12}.                                          

%% (progn (metapost-mode) (outline-minor-mode t) (setq fill-column 80))    

%% * (1) Local variables for Emacs.

%% Local Variables:
%% mode:metapost
%% eval:(outline-minor-mode t)
%% eval:(read-abbrev-file abbrev-file-name)
%% outline-regexp:"%% [*\f]+"
%% End:
