0

I'm trying to represent balls in radial metric using pgfplots and tikz.

Radial metric is a metric d in R^2 given by:

d( (a,b), (x,y) ) = p( (a,b), (x,y) ) if bx = ay

d( (a,b), (x,y) ) = p( (a,b), (0,0) ) + p( (0,0), (x,y) ) if bx =/= ay

Where p is the euclidean distance, so you can rewrite it as follows:

d( (a,b), (x,y) ) = sqrt( (x-a)^2 + (y-b)^2 ) if bx = ay

d( (a,b), (x,y) ) = sqrt(a^2 + b^2) + sqrt(x^2 + y^2) if bx =/= ay

I've graphicated in desmos, you can see the form of any ball by any center of radius here

I'd like to write a general expression for those balls, in such a way that if I want to plot two different balls, in order to plot the second one, the only thing I have to do is to change the center and the radius of the first one.

I've read some posts about plotting an implicit function using tikz, but I can't see the way that could help me.

Blooment
  • 666
  • 2
    Welcome to TeX.SX! Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. – TobiBS Aug 09 '20 at 12:01
  • @TobiBS Thank you for the advice, I did not know anything about this community rules. And I didn't know which would be a good start point learning to draw in LaTeX and LaTeX itself. "vi pa" answer gave me a start point, and I'm very thankful you didn't erase my question. Now, I investigate my own problem and present a MWE in all my questions. So, another time, thanks. – Blooment Aug 26 '20 at 10:03

1 Answers1

2

This is a first try.

\documentclass[border=3mm,tikz]{standalone}
\usetikzlibrary{calc,math}
\usetikzlibrary {shapes.misc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\newcommand{\dcircl}[3]{
\tikzmath{
\myr = #1;
\mya = #2;
\myb = #3;
\p1 = ifthenelse(\mya==0, 0, \mya + sqrt((\mya^2 * \myr^2)/(\mya^2 + \myb^2)));
\q1 = ifthenelse(\mya==0, \myb + \myr, \p1 * (\myb / \mya));
\p2 = ifthenelse(\mya==0, 0, \mya - sqrt((\mya^2 * \myr^2)/(\mya^2 + \myb^2)));
\q2 = ifthenelse(\mya==0, \myb - \myr, \p2 * (\myb / \mya));
\d1 = veclen(\mya,\myb);
\radius = ifthenelse(\d1 < \myr, \myr - \d1, 0);
}
\draw[dashed,green!50!black,fill=green!80!black,opacity=0.4] (0,0) circle[radius=\radius];
\node[inner sep=2pt,cross out,draw] at (axis cs:\mya,\myb){};
\draw[red,opacity=0.5] (axis cs:\p1,\q1) -- (axis cs:\p2,\q2);
\filldraw[fill=white,draw=red,draw opacity=0.7] (axis cs:\p1,\q1) circle[radius=2pt];
\filldraw[fill=white,draw=red,draw opacity=0.7] (axis cs:\p2,\q2) circle[radius=2pt];
}
\begin{document}
\begin{tikzpicture}[line width=1pt]
\begin{axis}[
axis y line=center,
axis x line=center,
axis equal,
xmin=-6, xmax=6, ymin=-6.5, ymax=6.5
]
\dcircl{3.2}{1.7}{0.8}%dcircl{r}{a}{b}
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

vi pa
  • 3,394