I'm trying to create TikZ diagram to represent the HDD platter. On the platter the track, sector and blocks should be highlighted. I moved from the simple by-the-hand calculated render more onto the systematic approach using variables and calculations and it almost works. The problem I have is with the matching of the lines drawn before the "highlighter" takes action (as shown in the picture bellow). Fumbling with the values little bit I found comibination which is usabe for my usecase, I still wonder and cannot figure out, where does the misalignment comes from.
PS.: I'm using Overleaf to write and render TeX files.
TikZ HDD schematic:
% Hard disk drive platter
% Author: Tomáš Michalek
%
% This diagram attempts to create HDD platter with the selectable track,
% sector and block highlighting.
%
% Current version is quite fragile and any improvements are welcome
%
\documentclass[tikz,margin=10pt]{standalone}
\usepackage{tikz}
\usepackage{comment}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% CUSTOMISATIONS
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\numTracks{8}
\def\numSectors{12}
\def\selectedTrack{6} % Track to highlight, negative values disable the selection
\def\selectedSector{0} % Sector to highlight, negative values disable the selection
\definecolor{baseColor}{RGB}{18, 54, 69} % Basic lines and borders
\definecolor{accentColor}{RGB}{1, 103, 143} % Selection
\definecolor{highlightColor}{RGB}{221, 109, 16} % Crossover of two selections
\pgfmathsetmacro\firstTrack{10cm}
\pgfmathsetmacro\lastTrack{2cm}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% CALCULATIONS
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfmathtruncatemacro{\trackStepRange}{\firstTrack-\lastTrack}
\pgfmathsetmacro\trackStep{\trackStepRange/\numTracks}
\pgfmathsetmacro\sectorStep{360/\numSectors}
\pgfmathtruncatemacro{\selectedSectorStart}{-\sectorStep*\selectedSector} % natural rotation
\pgfmathtruncatemacro{\selectedBlockStart}{\firstTrack-\selectedTrack*\trackStep}
\pgfmathtruncatemacro{\selectedBlockEnd}{\selectedBlockStart-\trackStep}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DRAWING
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Draw track lines
\foreach \track in {0,...,\numTracks} {
\draw [baseColor!20] (0,0) circle (\firstTrack-\track*\trackStep);
}
% Draw sector lines
\foreach \i in {0, \sectorStep, ..., 359}
\draw [baseColor!20] (\i:\firstTrack) -- (\i:\lastTrack);
\foreach \sector in {0, \sectorStep, ..., 359} {
\pgfmathparse{mod(\sector, \sectorStep*2)}
\pgfmathtruncatemacro{\remainder}{\pgfmathresult}
\ifnum\remainder=0
\pgfmathtruncatemacro{\sectorTint}{50};
\else
\pgfmathtruncatemacro{\sectorTint}{50}; %25
\fi
% If the `track` is selected, highlight it
\ifnum\selectedTrack>-1
\fill[accentColor!\sectorTint] (\sector:\selectedBlockStart) arc (\sector:\sector+\sectorStep:\selectedBlockStart) -- (\sector+\sectorStep:\selectedBlockEnd) arc (\sector+\sectorStep:\sector:\selectedBlockEnd) -- cycle;
\fi
}
% If the `sector` is selected, highlight it
\ifnum\selectedSector>-1
\fill[accentColor!30, rotate=\selectedSectorStart] (0:\firstTrack) arc (0:\sectorStep:\firstTrack) -- (\sectorStep:\lastTrack) arc (\sectorStep:0:\lastTrack) -- cycle;
\fi
% If both `sector` and `track` are selected, highlight `block`
\ifnum\selectedSector>-1
\ifnum\selectedTrack>-1
\fill[highlightColor!80, rotate=\selectedSectorStart] (0:\selectedBlockStart) arc (0:\sectorStep:\selectedBlockStart) -- (\sectorStep:\selectedBlockEnd) arc (\sectorStep:0:\selectedBlockEnd) -- cycle;
\fi
\fi
\end{tikzpicture}
\end{document}