IAM

OPENSOURCEFAN STUDYING
STUDYINGCOMPUTERSCIENCEANDMATH COMPUTERSCIENCE

Check out the latest superpixel benchmark — Superpixel Benchmark (2016) — and let me know your opinion! @david_stutz
09thJANUARY2017

SNIPPET

Realistic voronoi cells in LaTeX using Tikz – given a set of center points, the voronoi cells are calculated using MatLab. The example is part of a collection of LaTeX snippets available on GitHub.

voronoi.tex
\documentclass[11pt]{article}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{subfigure}

\usepackage[font=footnotesize]{caption}
\usepackage{pgfplots}
\usepackage{tikz}

% Scriptsize axis style.
\pgfplotsset{every axis/.append style={tick label style={/pgf/number format/fixed},font=\scriptsize,ylabel near ticks,xlabel near ticks,grid=major}}

\begin{document}

\begin{figure}
	\begin{tikzpicture}[samples=100,smooth]
		\begin{scope}
			\clip(-4,-1) rectangle (4,4);
			\draw plot[domain=0:360] ({cos(\x)*sqrt(20/(sin(2*\x)+2))},{sin(\x)*sqrt(20/(sin(2*\x)+2))});
			\draw plot[domain=0:360] ({cos(\x)*sqrt(16/(sin(2*\x)+2))},{sin(\x)*sqrt(16/(sin(2*\x)+2))});
			\draw plot[domain=0:360] ({cos(\x)*sqrt(12/(sin(2*\x)+2))},{sin(\x)*sqrt(12/(sin(2*\x)+2))});
			\draw plot[domain=0:360] ({cos(\x)*sqrt(8/(sin(2*\x)+2))},{sin(\x)*sqrt(8/(sin(2*\x)+2))});
			\draw plot[domain=0:360] ({cos(\x)*sqrt(4/(sin(2*\x)+2))},{sin(\x)*sqrt(4/(sin(2*\x)+2))});
			\draw plot[domain=0:360] ({cos(\x)*sqrt(1/(sin(2*\x)+2))},{sin(\x)*sqrt(1/(sin(2*\x)+2))});
			\draw plot[domain=0:360] ({cos(\x)*sqrt(0.0625/(sin(2*\x)+2))},{sin(\x)*sqrt(0.0625/(sin(2*\x)+2))});
			
			\draw[->,blue,ultra thick] (-2,3.65) to (-1.93,3);
			\draw[->,blue,ultra thick] (-1.93,3) to (-1.75,2.4);
			\draw[->,blue,ultra thick] (-1.75,2.4) to (-1.5,1.8);
			\draw[->,blue,ultra thick] (-1.5,1.8) to (-1.15,1.3);
			
			\node at (-1.4,3.8){\scriptsize $w[0]$};
			\node at (-1.2,3.2){\scriptsize $w[1]$};
			\node at (-1.05,2.6){\scriptsize $w[2]$};
			\node at (-0.8,2){\scriptsize $w[3]$};
			\node at (-0.6,1.4){\scriptsize $w[4]$};
		\end{scope}
	\end{tikzpicture}
\end{figure}

\end{document}
voronoi_sample.m
points = dlmread('points.txt');
[vx,vy]=voronoi(points(:,1), points(:,2));
fid = fopen('voronoi.txt', 'w');
fprintf(fid, '%f, %f\n%f %f\n\n', [vx(:), vy(:)]');
fclose(fid);
fid = fopen('voronoi.txt', 'w');
fprintf(fid, '%f %f\n%f %f\n\n', [vx(:), vy(:)]');
fclose(fid);
pointx.txt
-0.5   2.5
1   4
4   1
2   6
3   5
4   3
6   2
8   3.5
7   1
voronoi.pdf
voronoi

What is your opinion on the code snippet? Is it working? Let me know your thoughts in the comments below or using the following platforms: