# How to draw the diameter of a domain in Tikz?

I am writing a short document on basic Set Theory and would like to include a few images. The first definition which I have been unable to draw for myself is the diameter.

The diameter of a non-empty set A of n-dimensional Euclidean space is the largest distance apart of any pair of points in A; |A|=sup(|x-y | : x and y are in A).

What I'd like Tikz to draw for me is this:

where the shape of A is a 'random' blob. and x and y are calculated, labelled, and joined automatically. And then |A| is drawn and labelled underneath (again automatically).

Does someone know how to do this? Thanks in advance.

• Is there a good reason to have x and y calculted automatically? As I understand the question you want some illustrations for a set theory description, not the actual derivations. If you really want it automatic, there are some other questions. Like how do you generate the random blobs? Are there any restrictions? (The general case is very general). I would instead suggest to create one fixed random blob and draw fixed x and y, as in the figure you have given. That is a good illustration of the text you describe. – StefanH Jul 9 '17 at 10:52
• The calculation is just for my 'perfectionism' of it being random each time you do it - thought it would be pretty cool :) – JSharpee Jul 9 '17 at 10:53
• I can agree on that it might be cool, but as a good illustration I am not so convinced about having the blob random. The random shape might not always capture all you want. So I still think you need restrictions. And an example of how you intend to create random blob. – StefanH Jul 9 '17 at 11:02
• @StefanH There is an example of a random shape formation here: tex.stackexchange.com/questions/126144/…, although I haven't found a way of filling the shape with a colour. – JSharpee Jul 9 '17 at 11:11
• The worst random blobs always come from math people. Why do you need a random blob? Find good corner cases and show explicitly the actual concept. Everytime someone says "think of a set" people draw this. In your picture, you leave the nonconvexity problem to your reader for example should the path consist of points which are also in A ? Or not? If I take a hollow disk should I connect over the center point? and stuff like this... – percusse Jul 9 '17 at 23:07

A brutal idea: The following decoration will mark ninety milestones along the given path.

\documentclass[border=9,tikz]{standalone}
\usetikzlibrary{calc,decorations}

\pgfdeclaredecoration{mark milestone}{initial}{
\state{initial}[width=0pt,next state=mark]{
\xdef\markmilestoneindex{0}
\xdef\markmilestonename{\csname tikz@fig@name\endcsname}
\pgfmathsetmacro\markmilestonesep{\pgfdecoratedpathlength/90}
\xdef\markmilestonesep{\markmilestonesep}
}
\state{mark}[width=\markmilestonesep pt]{
\coordinate(\markmilestonename-\markmilestoneindex);
\pgfmathtruncatemacro\markmilestoneindex{\markmilestoneindex+1}
\xdef\markmilestoneindex{\markmilestoneindex}
}
\state{final}{
\pgftransformshift{\pgfpointdecoratedpathlast}
\coordinate(\markmilestonename-\markmilestoneindex);
}
}

\begin{document}
\begin{tikzpicture}
\draw[rounded corners,
postaction={name=irreshape,decorate,decoration=mark milestone}]
(0:2)foreach\i in{1,...,11}{--(\i*30:3+rnd)}--cycle
[sharp corners]; %https://tex.stackexchange.com/questions/38989/
\draw foreach\i[evaluate={\a=\i*4-180};]in{0,...,90}{
(irreshape-\i)circle(.4pt)node[anchor=\a]{\tiny\i}
};
\end{tikzpicture}
\end{document}


Now you can calculate the lengths of the four thousands and five segments formed by these points and see who is the longest.

• ... and how long does it take (LOL)? BTW, +1. – CarLaTeX Jul 10 '17 at 3:35
• @CarLaTeX Maybe long not so long. It will be easier than a 100 by 100 surface plot in pgfplots.... The perfect idea is to deal with the underlying Bezier curves. But it will take even more time. – Symbol 1 Jul 10 '17 at 3:45
• Now I wanna try :), thank you for your explanation! – CarLaTeX Jul 10 '17 at 3:49