\usetikzlibrary{calc} % Load the calc library for coordinate calculations

\begin{tikzpicture}[scale=1.8]
    % --- Global Definitions and Calculations ---
    % \definecolor{myred}{RGB}{200,0,0}  % Red color for rectangle fill
    \newcommand{\pointsize}{0.04}  % Change this to modify all point sizes
    \newcommand{\rectwidth}{0.08}  % Width of the rectangles

    % Define desired gap between diagrams (in TikZ units)
    \newcommand{\interDiagramGapValue}{0.8} % Results in 1.6cm gap on paper due to scale=2

    % Approximate local x-extents for each diagram
    \pgfmathsetmacro{\valXMinLocalOne}{-0.1}
    \pgfmathsetmacro{\valXMaxLocalOne}{2.2}
    \pgfmathsetmacro{\valXMinLocalTwo}{-0.125}
    \pgfmathsetmacro{\valXMaxLocalTwo}{1.875}
    \pgfmathsetmacro{\valXMinLocalThree}{-0.1}
    \pgfmathsetmacro{\valXMaxLocalThree}{2.2}

    % Calculate x-shifts for equal spac, 
    % Shift for Diagram 1 is 0
    \pgfmathsetmacro{\xShiftTwoVal}{\valXMaxLocalOne - \valXMinLocalTwo + \interDiagramGapValue}
    \pgfmathsetmacro{\xShiftThreeVal}{\xShiftTwoVal + \valXMaxLocalTwo - \valXMinLocalThree + \interDiagramGapValue}

    % Y-position for labels (relative to local y=0 of each diagram)
    % Estimated lowest y-extent of Diagram 3 is around -0.57.
    % So, -0.9 should place labels clearly below all diagrams.
    \newcommand{\labelYPos}{-0.5}

    % Approximate local x-centers for labels
    \pgfmathsetmacro{\labelXPosOne}{(\valXMinLocalOne + \valXMaxLocalOne) / 2}
    \pgfmathsetmacro{\labelXPosTwo}{(\valXMinLocalTwo + \valXMaxLocalTwo) / 2}
    \pgfmathsetmacro{\labelXPosThree}{(\valXMinLocalThree + \valXMaxLocalThree) / 2}

    % --- Example 1: Five Points with Multiple Lines (Diagram A) ---
    \begin{scope}[xshift=0cm] % No shift for the first diagram
        \newcommand{\rectLenOne}{0.8} % Length of rectangles in Example 1
        \coordinate (A) at (0.3, 0.3);
        \coordinate (B) at (1.8, 0.4);
        \coordinate (C) at (0.5, 1.8);
        \coordinate (D) at (1.7, 1.6);
        \coordinate (E) at (1.0, 1.0);
        
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={10:(A)}] ($(A)-(\rectLenOne/2, \rectwidth/2)$) rectangle ($(A)+(\rectLenOne/2, \rectwidth/2)$);
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={100:(A)}] ($(A)-(\rectLenOne/2, \rectwidth/2)$) rectangle ($(A)+(\rectLenOne/2, \rectwidth/2)$);
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={-140:(A)}] ($(A)-(\rectLenOne/2, \rectwidth/2)$) rectangle ($(A)+(\rectLenOne/2, \rectwidth/2)$);
        
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={10:(B)}] ($(B)-(\rectLenOne/2, \rectwidth/2)$) rectangle ($(B)+(\rectLenOne/2, \rectwidth/2)$);
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={80:(B)}] ($(B)-(\rectLenOne/2, \rectwidth/2)$) rectangle ($(B)+(\rectLenOne/2, \rectwidth/2)$);
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={150:(B)}] ($(B)-(\rectLenOne/2, \rectwidth/2)$) rectangle ($(B)+(\rectLenOne/2, \rectwidth/2)$);
        
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={25:(C)}] ($(C)-(\rectLenOne/2, \rectwidth/2)$) rectangle ($(C)+(\rectLenOne/2, \rectwidth/2)$);
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={115:(C)}] ($(C)-(\rectLenOne/2, \rectwidth/2)$) rectangle ($(C)+(\rectLenOne/2, \rectwidth/2)$);
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={-110:(C)}] ($(C)-(\rectLenOne/2, \rectwidth/2)$) rectangle ($(C)+(\rectLenOne/2, \rectwidth/2)$);
        
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={-75:(D)}] ($(D)-(\rectLenOne/2, \rectwidth/2)$) rectangle ($(D)+(\rectLenOne/2, \rectwidth/2)$);
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={15:(D)}] ($(D)-(\rectLenOne/2, \rectwidth/2)$) rectangle ($(D)+(\rectLenOne/2, \rectwidth/2)$);
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={135:(D)}] ($(D)-(\rectLenOne/2, \rectwidth/2)$) rectangle ($(D)+(\rectLenOne/2, \rectwidth/2)$);
        
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={-35:(E)}] ($(E)-(\rectLenOne/2, \rectwidth/2)$) rectangle ($(E)+(\rectLenOne/2, \rectwidth/2)$);
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={60:(E)}] ($(E)-(\rectLenOne/2, \rectwidth/2)$) rectangle ($(E)+(\rectLenOne/2, \rectwidth/2)$);
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={180:(E)}] ($(E)-(\rectLenOne/2, \rectwidth/2)$) rectangle ($(E)+(\rectLenOne/2, \rectwidth/2)$);
        
        \filldraw[fill=myyellow, draw=black, thick] (A) circle (\pointsize);
        \filldraw[fill=myyellow, draw=black, thick] (B) circle (\pointsize);
        \filldraw[fill=myyellow, draw=black, thick] (C) circle (\pointsize);
        \filldraw[fill=myyellow, draw=black, thick] (D) circle (\pointsize);
        \filldraw[fill=myyellow, draw=black, thick] (E) circle (\pointsize);

        % Label for Diagram A
        \node at (\labelXPosOne, \labelYPos) {$A$};
    \end{scope}
    
    % --- Example 2: 8x8 Grid with Lines Through Points (Diagram B) ---
    \begin{scope}[xshift=\xShiftTwoVal cm]
        \foreach \x in {0,0.25,0.5,0.75,1,1.25,1.5,1.75} {
            \foreach \y in {0,0.25,0.5,0.75,1,1.25,1.5,1.75} {
                \filldraw[fill=myyellow, draw=black, thick] (\x, \y) circle (\pointsize);
            }
        }
        \draw[fill=myred, fill opacity=0.2, draw=black] (-0.125, {0.5-\rectwidth/2}) rectangle (1.875, {0.5+\rectwidth/2});
        \draw[fill=myred, fill opacity=0.2, draw=black] ({0.75-\rectwidth/2}, -0.125) rectangle ({0.75+\rectwidth/2}, 1.875);
        \coordinate (diag1center) at (0.875,1.125);
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={45:(diag1center)}] ($(diag1center)-(1.06, \rectwidth/2)$) rectangle ($(diag1center)+(1.06, \rectwidth/2)$);
        \coordinate (diag2center) at (0.75,0.75);
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={-45:(diag2center)}] ($(diag2center)-(1.06, \rectwidth/2)$) rectangle ($(diag2center)+(1.06, \rectwidth/2)$);
        \coordinate (slope13center) at (0.875,0.625);
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={18.43:(slope13center)}] ($(slope13center)-(1.0, \rectwidth/2)$) rectangle ($(slope13center)+(1.0, \rectwidth/2)$);
        % \coordinate (slope3center) at (0.625,1.125);
        % \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={71.57:(slope3center)}] ($(slope3center)-(1.0, \rectwidth/2)$) rectangle ($(slope3center)+(1.0, \rectwidth/2)$);

        % Label for Diagram B
        \node at (\labelXPosTwo, \labelYPos) {$B$};
    \end{scope}
    
    % --- Example 3: Skewed Hourglass with 5 Rectangles (Diagram C) ---
    \begin{scope}[xshift=\xShiftThreeVal cm]
        \newcommand{\rectLThreeA}{2.2} % Length for R1, R2
        \newcommand{\rectLThreeB}{1.9} % Length for R3, R4
        \newcommand{\rectLFive}{2.2}   % Length for R5

        % Rectangle Centers and Angles
        \coordinate (C1) at (0.9, 1.1); \newcommand{\angleOne}{-55} 
        \coordinate (C2) at (1.1, 0.9); \newcommand{\angleTwo}{65}
        \coordinate (C3) at (1.0, 1.50);\newcommand{\angleThree}{10} 
        \coordinate (C4) at (1.0, 0.38);\newcommand{\angleFour}{-10}
        \coordinate (C5) at (1.0, 1.05);\newcommand{\angleFive}{35}
        \coordinate (C6) at (1.0, 0.75);\newcommand{\angleSix}{-30}

        % Define directional points for centerline intersections
        \coordinate (C1dir) at ($(C1)+({cos(\angleOne)},{sin(\angleOne)})$);
        \coordinate (C2dir) at ($(C2)+({cos(\angleTwo)},{sin(\angleTwo)})$);
        \coordinate (C3dir) at ($(C3)+({cos(\angleThree)},{sin(\angleThree)})$);
        \coordinate (C4dir) at ($(C4)+({cos(\angleFour)},{sin(\angleFour)})$);
        \coordinate (C5dir) at ($(C5)+({cos(\angleFive)},{sin(\angleFive)})$);
        \coordinate (C6dir) at ($(C6)+({cos(\angleSix)},{sin(\angleSix)})$);

        % Draw Rectangles R1-R5
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={\angleOne:(C1)}] ($(C1)-(\rectLThreeA/2, \rectwidth/2)$) rectangle ($(C1)+(\rectLThreeA/2, \rectwidth/2)$); %R1
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={\angleTwo:(C2)}] ($(C2)-(\rectLThreeA/2, \rectwidth/2)$) rectangle ($(C2)+(\rectLThreeA/2, \rectwidth/2)$); %R2
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={\angleThree:(C3)}] ($(C3)-(\rectLThreeB/2, \rectwidth/2)$) rectangle ($(C3)+(\rectLThreeB/2, \rectwidth/2)$); %R3
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={\angleFour:(C4)}] ($(C4)-(\rectLThreeB/2, \rectwidth/2)$) rectangle ($(C4)+(\rectLThreeB/2, \rectwidth/2)$); %R4
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={\angleFive:(C5)}] ($(C5)-(\rectLFive/2, \rectwidth/2)$) rectangle ($(C5)+(\rectLFive/2, \rectwidth/2)$); %R5
        \draw[fill=myred, fill opacity=0.2, draw=black, rotate around={\angleSix:(C6)}] ($(C6)-(\rectLFive/2, \rectwidth/2)$) rectangle ($(C6)+(\rectLFive/2, \rectwidth/2)$); %R5
        
        % Intersection points (R1-R5)
        \coordinate (P13) at (intersection of C1--C1dir and C3--C3dir); % R1 x R3 (Recalculated)
        \coordinate (P14) at (intersection of C1--C1dir and C4--C4dir); % R1 x R4 (Recalculated)
        \coordinate (P15) at (intersection of C1--C1dir and C5--C5dir); % R1 x R5
        \coordinate (P35) at (intersection of C3--C3dir and C5--C5dir); % R3 x R5
        \coordinate (P45) at (intersection of C4--C4dir and C5--C5dir); % R4 x R5

        % Random points (PR1-PR8)
        \coordinate (PR1) at (0.3, 0.9);
        \coordinate (PR2) at (0.75, 0.7);
        \coordinate (PR3) at (1.5, 1.4);
        \coordinate (PR4) at (1.0, 1.3);
        \coordinate (PR5) at (1.1, 1.7);
        \coordinate (PR6) at (1.15, 0.5);
        \coordinate (PR7) at (0.5, 0.467);
        \coordinate (PR8) at (1.05, 0.2);
        \coordinate (PR9) at (0.4, 0.25);
        \coordinate (PR10) at (0.6, 1.2);
        \coordinate (PR11) at (0.2, 1.6);
        \coordinate (PR12) at (1.5, 0.9);
        
        % Draw all 5 intersection points.
        \filldraw[fill=myyellow, draw=black, thick] (P13) circle (\pointsize);
        \filldraw[fill=myyellow, draw=black, thick] (P14) circle (\pointsize);
        \filldraw[fill=myyellow, draw=black, thick] (P15) circle (\pointsize);
        \filldraw[fill=myyellow, draw=black, thick] (P35) circle (\pointsize);
        \filldraw[fill=myyellow, draw=black, thick] (P45) circle (\pointsize);

        % Draw unrelated points
        \filldraw[fill=myyellow, draw=black, thick] (PR1) circle (\pointsize);
        \filldraw[fill=myyellow, draw=black, thick] (PR2) circle (\pointsize);
        \filldraw[fill=myyellow, draw=black, thick] (PR3) circle (\pointsize);
        \filldraw[fill=myyellow, draw=black, thick] (PR4) circle (\pointsize);
        \filldraw[fill=myyellow, draw=black, thick] (PR5) circle (\pointsize);
        \filldraw[fill=myyellow, draw=black, thick] (PR6) circle (\pointsize);
        \filldraw[fill=myyellow, draw=black, thick] (PR7) circle (\pointsize);
        \filldraw[fill=myyellow, draw=black, thick] (PR8) circle (\pointsize);
        \filldraw[fill=myyellow, draw=black, thick] (PR9) circle (\pointsize);
        \filldraw[fill=myyellow, draw=black, thick] (PR10) circle (\pointsize);
        \filldraw[fill=myyellow, draw=black, thick] (PR11) circle (\pointsize);
        \filldraw[fill=myyellow, draw=black, thick] (PR12) circle (\pointsize);

        % Label for Diagram C
        \node at (\labelXPosThree, \labelYPos) {$C$};
    \end{scope}
\end{tikzpicture}
