%% to be compiled with pdflatex

\documentclass{amsart}

%%%%%%%%

\newif\ifNAMES %
%% uncomment to show the names of the 14 vertices
%%% recommended if you read this file
% \NAMEStrue %

%%%%%%%%

\newif\ifVAR %
%% subdivide 1:1:2
% \VARtrue % no effect with \SKEWtrue

\newif\ifVARVAR %
%% subdivide 2:1:1
% \VARVARtrue % no effect with \SKEWtrue
\ifVARVAR\VARtrue\fi %

\newif\ifSKEW %
%% subdivide evenly, some faces are not rectangles
% \SKEWtrue % overrides \ifVAR, \ifVARVAR

%%%%%%%%

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\thispagestyle{empty}

\centerline{%
  \tikzpicture

  %%%% 14 vertices

  %% 5 points in back (= M_3, the pentagon)
  \coordinate (A0) at (0,0,0) ; % origin (M_1)
  \coordinate (A1) at (0,-4,0) ; % basis vector 1 (in M_2)
  \coordinate (A2) at (-4,0,0) ; % basis vector 2
  \coordinate (A3) at ($(A1)+(A2)$) ; % (1,1,0) %% basis coordinate
  %% subdivision for M_3
  \coordinate (X0) at ($(A0)!1/2!(A2)$) ; % (0,1/2,0)

  %%%% remaining vertices of M_4

  %% 5 points in front (= opposite M_3 in M_4)
  \coordinate (B0) at (0,0,8) ; % basis vector 3
  \coordinate (B1) at ($(A1)+(B0)$) ; % (1,0,1)
  \coordinate (B2) at ($(A2)+(B0)$) ; % (0,1,1)
  \coordinate (B3) at ($(A3)+(B0)$) ; % (1,1,1)
  \coordinate (X2) at ($(X0)+(B0)$) ; % (0,1/2,1)

  %% 4 inner subdivisions

  \ifSKEW %

  %% subdivide each rail evenly
  \def\StepA{1/3} %
  \def\StepB{2/3} %
  \def\StepC{1/2} %
  \let\StepD\StepC %

  \else % \ifSKEW

  \ifVAR

  \ifVARVAR % subdivide 2:1:1
  \def\StepA{1/2} %
  \def\StepB{3/4} %
  \else % subdivide 1:1:2
  \def\StepA{1/4} %
  \def\StepB{1/2} %
  \fi

  \else % subdivide 1:1:1
  \def\StepA{1/3} %
  \def\StepB{2/3} %
  \fi

  %% get rectangles
  \let\StepC\StepB %
  \let\StepD\StepA %

  \fi % \ifSKEW

  \coordinate (X1) at ($(X0)!\StepC!(X2)$) ; % (0,1/2,2/3)
  \coordinate (Y1) at ($(A0)!\StepA!(B0)$) ; % (0,0,1/3)
  \coordinate (Y2) at ($(A0)!\StepB!(B0)$) ; % (0,0,2/3)
  \coordinate (Z1) at ($(A1)!\StepD!(B1)$) ; % (1,0,1/3)

  %%%%%%%%

  %% placement in shipout is independent of labels, thickness of
  %% bullets
  \useasboundingbox (A0) (B2) ; %

  %%%%%%%% draw the cube

  %%%% https://tex.stackexchange.com/questions/28284/how-to-draw-a-cube-with-tikz-where-all-faces-have-a-distinct-color
  %%%% https://tex.stackexchange.com/a/28286

  %%%% using it without change

  \draw[blue,fill=yellow!80] (A1) -- (B1) -- (B3) -- (A3) -- cycle ; % Bottom Face
  \draw[blue,fill=blue!30] (A0) -- (A1) -- (A3) -- (A2) -- cycle ; % Back Face
  \draw[blue,fill=red!10] (A2) -- (B2) -- (B3) -- (A3) -- cycle ; % Left Face
  \draw[blue,fill=red!20,opacity=0.8] (A0) -- (B0) -- (B1) -- (A1) -- cycle ; % Right Face
  \draw[blue,fill=red!20,opacity=0.6] (B0) -- (B2) -- (B3) -- (B1) -- cycle ; % Front Face
  \draw[blue,fill=red!20,opacity=0.8] (A0) -- (A2) -- (B2) -- (B0) -- cycle ; % Top Face

  %%%%%%

  %%%% 3 subdivisions

  \draw (X0) -- (X2) ; %
  \draw (X1) -- (Y2) ; %
  \draw (Y1) -- (Z1) ; %

  %%%% bullets

  \foreach \XXX in {%
    %%%% show only the points necessary for the subdivision
    %%% these are shown in assoc1.pdf to indicate immediate chains of
    %%% length 2 from the front to the back
    %% A2, A3, B2, B3, % left
    %% A0, A1, % back right
    %% B0, B1, % front right
    X0, X1, X2, Y1, Y2, Z1%
  }{
    \fill (\XXX) circle[radius=2.2pt] ; %
  }

  %%%%%%%% show the names of the 14 vertices
  \ifNAMES

  \foreach \XXX/\place in {%
    A0/below left, A1/above left, A2/below right, A3/above right, %
    B0/below left, B1/above left, B2/below right, B3/above right, %
    X0/below right, X1/above left, X2/above left, %
    Y1/below right, Y2/below right, Z1/above left%
  }{
    \node[\place,inner sep=2pt] at (\XXX) {\XXX}; %
  }

  \fi % \ifNAMES

  \endtikzpicture
} % \centerline
\end{document}

%%%%%%%%

%% png creation (normal size, transparent)

%%% pdflatex cube-3.tex
%%% pdftocairo -png -singlefile -transp cube-3.pdf tmp
%%% magick -define png:exclude-chunk=date,time tmp.png -crop 429x429+423+236 +repage cube-3.png
%%% optipng cube-3.png

%%%% Default resolution of pdftocairo is 150 ppi.

%%%% magick adds white (fallback) background to the transparent image.

%%%% trim parameters:
%%% magick tmp.png -format "%@\n" info: %% 421x424+427+237

%%%% Added padding (after trimming) to get the cube boundaries
%%%% symmetric.

%% png creation (small size, transparent)

%%% pdftocairo -png -singlefile -transp -r 100 cube-3.pdf tmp-small
%%% magick -define png:exclude-chunk=date,time tmp-small.png -crop 286x285+282+158 +repage cube-3-small.png
%%% optipng cube-3-small.png

%%%% trim parameters:
%%% magick tmp-small.png -format "%@\n" info: %% 282x283+284+158

%% program versions

%%% This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019/Debian) (preloaded format=pdflatex)
%%% Document Class: amsart 2017/10/31 v2.20.4
%%% Package: tikz 2020/01/08 v3.1.5b (3.1.5b)

%%% pdftocairo version 0.86.1
%%% ImageMagick 7.1.1-43 Q16-HDRI x86_64 22550 https://imagemagick.org
%%% OptiPNG version 0.7.7

%%%%%%%%

%% versions

%%%% cube-3.png (former variant, get it now with \SKEWtrue):
%%% 2024-12-29 first version

%%%% cube-3.png (new basic variant with \VARfalse, \SKEWfalse)
%%% 2025-08-14 first version

%% latest changes

%%%% Latest change of an image:
%%% 2025-08-21 (padding corrected)

%%%% Latest code change:
%%% 2025-08-14
%%% 2025-09-03 (implement \ifVARVAR)

%%%% Latest change of comments:
%%% 2025-08-21

%%%%%%%%
