How can I draw (and paint) Voronoi regions of a series of points in plane using Tikz? How about if the points are in 3d space?
[Tex/LaTex] How to draw (and paint) the Voronoi regions of a series of points using Tikz
tikz-pgf
Related Solutions
Using shorten > = <negative length>
and shorten < = <negative length>
will extend the curve with curved line segments. If the distances are short, and the curvature is small, this might be all you need, however, as Altermundus pointed out, if your curvature is large, the line will not pass through the defined points any more.
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\begin{document}
%
\begin{tikzpicture}
%
\coordinate (n_3) at (1,1);
\coordinate (h_1) at (3,1.5);
%dots
\fill[blue] (n_3) circle (2pt);
\fill[blue] (h_1) circle (2pt);
%Left curve
\draw [shorten >=-0.4cm,shorten <=-0.4cm] (n_3) to [bend right=5](h_1);
%
\end{tikzpicture}
%
\end{document}
It's possible to fill the area in the background (layers)
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{scalefnt}
\usepackage[T1]{fontenc} % Usual fonts
\usepackage{tgheros,textcomp}% Fonts
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
\def\magnif{4} %picture magnification ratio
\def\KeyAngle{0} %Angular position of key
\def\DiaShellMachining{0.925}
\def\DiaExtKey{.76}
\def\DiaExt{0.63}
\def\DiaInt{0.5}
\def\KeyWidth{0.32}
{\scalefont{3.1}
\begin{tikzpicture}[scale=\magnif]
\clip (-1,-1) rectangle (1,1);
\draw [gray] (0,0) circle (\DiaShellMachining/2);
\draw [](0.31, 0.57) node (one) {1}; % first engraved characters
\draw [](0.09, 0.6) node (two) {2};
\draw [] (-0.16, 0.6) node (three) {3};
\draw [] (-0.37, 0.55) node (four) {4};
\draw [](-0.31,-0.5) node (five) {5};
\draw [] (0.345,-0.5) node (six) {6}; %last engraved character
\draw [very thick, color=gray, rounded corners=10mm] (0.49750,-0.5225) rectangle (2.91,.8225); %Shell
\draw [very thick, color=gray, rounded corners=10mm] (-0.49750,-0.5225) rectangle (-2.91,.8225); %Shell
\draw [ultra thick, color=gray] (-2, 0.9075) -- (2, 0.9075);%Shell upper limit
\draw [ultra thick, color=gray] (-2, -0.6075) -- (2, -0.6075);%Shell lower limit
\fill[orange,even odd rule] (0,0) circle(\DiaInt/2) circle(\DiaExt/2); %Painted ring at front of key
\begin{scope}[rotate=\KeyAngle]
\pgfmathparse{0.5*\DiaExtKey*cos(asin (\KeyWidth/(\DiaExtKey)))} \let\Youter\pgfmathresult
\pgfmathparse{0.5*\DiaExt*cos(asin (\KeyWidth/(\DiaExt)))} \let\Yinner\pgfmathresult
\draw [color=black] (-0.5*\KeyWidth, \Youter) node (a) {.};
\draw [color=red] (0.5*\KeyWidth, \Youter) node (b) {.};
\draw [color=blue] (0.5*\KeyWidth, \Yinner) node (c) {.};
\draw [color=green] (-0.5*\KeyWidth, \Yinner) node (d) {.};
\pgfmathparse{(\Youter) / (0.5*\KeyWidth)} \let\ThetaOne\pgfmathresult % Y coordinate of upper key corners
\pgfmathparse{(\Yinner) / (0.5*\KeyWidth)} \let\ThetaTwo\pgfmathresult %Y coordinate of lower key corners
\pgfmathparse{sqrt ((\Youter)^2)+((0.5*\KeyWidth) ^2 )} \let\ra\pgfmathresult
\fill[green!50,draw=black,thick] ({atan(\ThetaOne)}:\ra) -- ({atan(\ThetaTwo)}:0.5*\DiaExt) arc ({atan(\ThetaTwo)}:{180-atan(\ThetaTwo)}:0.5*\DiaExt) -- ({180-atan(\ThetaOne))}:\ra) arc ({180-atan(\ThetaOne))}: {atan(\ThetaOne)}:\ra) ;
\end{scope}
\end{tikzpicture}
}%
\end{document}
Best Answer
Here is one solution using TikZ.
Some comments on the code :
\foreach
because clipping inside such a loop is not available outside the loop (\foreach
creates a group). So I'm overcoming this by using\xintFor
.