3

I really need a quick advice dealing with the answer given by sdaau. See this question. Actually I have a follow-up question regarding the given solution.

This works actually pretty fine, but the coords are a little off. Please see the screenshot. I can't get any closer to the drawn points. I sureley wnt to draw from at the generated nodes directly. They ssem to be at the expected locations, as can be seen from the orange circles. What is wrong using this code (since it doesn't compile either right now, after setting up the MWE)?

% !TEX TS-program = pdflatex
% !TEX encoding = UTF-8 Unicode

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{plotmarks, calc, intersections}
\usepackage{amsmath}

\begin{document}
\begin{tikzpicture}


\begin{axis}[%
    width=10cm,
    height=10cm,
    axis x line = middle,
    axis y line = middle,
    scale only axis,
    xlabel={x [mm]},
    ylabel={y [mm]},
    title={$\text{n}_{\text{iterations}}\text{= 2}$}
]


\addplot+[
  only marks,
  mark=text, 
  text mark={\coordindex}, % empty for now; try also \coordindex
  text mark as node=true,
  text mark style={%
    name=p\coordindex,
    color=orange,
    shape=circle,
    draw,
    inner sep=0pt,
    minimum size=0pt,
    align=center,
    text width=5pt,
    text depth=0pt
  }
]
  table{%
        0         0     
      -79.9393  236.8749 
      143.0014  350.0007
      200.0014  350.0000
      200.0008  300.0000
    };
    \pgfplotsextra{             
         % In this case, you get the point that is <dimension> away from <p> on the straight line to <q>:  ($(p)!dimension!(q)$)
        \path [name path=P--C-ext] (p0) -- ($(p1)!-50!(p0)$);
        \draw (p0) -- (p1);
        \path [name path=Rim] (p1.center) circle(50);
        \path [draw, name intersections={of=P--C-ext and Rim}];

        \pgfmathanglebetweenpoints{%
                \pgfpointanchor{p1}{center}
        }{%
                \pgfpointanchor{intersection-1}{center}
        }
        \let\myendresult\pgfmathresult

        \fill [fill=blue!50,draw=blue,thin,opacity=0.5] (p1) -- (intersection-1) arc [start angle=\myendresult,delta angle=-40,radius=50] -- cycle;
        \fill [fill=blue!50,draw=blue,thin,opacity=0.5] (p1) -- (intersection-1) arc [start angle=\myendresult,delta angle=25,radius=50] -- cycle;
    };

\end{axis}

\end{tikzpicture}

\end{document}

screenshot

4
  • 4
    I can't compile this. Can you include the preamble too? Please make it a full minimum-working example such that we can copy paste and reproduce your issue.
    – percusse
    Aug 16, 2014 at 13:39
  • Soory for hitting you guys without a working MWE. I found out during setting it up, I can't supply a working one. Something is just missing. I can't compile the same stuff and get the error "No shape named p0 is known.". I used to have \pgfplotsextra let be executed within the scope of \addplot and it worked. Now it doesn't... I'm a little stuck
    – goeck
    Aug 16, 2014 at 19:09
  • It seems that the nodes (p0) etc. are not defined until after the \end{axis}, at which point circle(50) becomes 50cm. Aug 17, 2014 at 1:17
  • Also, ($(p1)!-\radius!(p0)$) and (intersection-1) are at the same precise location. Aug 17, 2014 at 1:43

1 Answer 1

3
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{plotmarks, calc, intersections}
\usepackage{amsmath}

\newlength{\radius}

\begin{document}
\begin{tikzpicture}


\begin{axis}[%
    width=10cm,
    height=10cm,
    axis x line = middle,
    axis y line = middle,
    scale only axis,
    xlabel={x [mm]},
    ylabel={y [mm]},
    title={$\text{n}_{\text{iterations}}\text{= 2}$}
]

\addplot+[
  only marks,
  mark=text, 
  text mark={\coordindex}, % empty for now; try also \coordindex
  text mark as node=true,
  text mark style={%
    name=p\coordindex,
    color=orange,
    shape=circle,
    draw,
    inner sep=0pt,
    minimum size=0pt,
    align=center,
    text width=5pt,
    text depth=0pt
  }
]
  table{%
        0         0     
      -79.9393  236.8749 
     143.0014  350.0007
     200.0014  350.0000
      200.0008  300.0000
    };

\coordinate (R) at (50,50);% store radius as coordinate
\end{axis}

\pgfextractx{\radius}{\pgfpointanchor{R}{center}}

\coordinate (pext) at ($(p1)!-\radius!(p0)$);
\draw (p0) -- (p1) (p1) -- (pext);

\pgfmathanglebetweenpoints{\pgfpointanchor{p0}{center}}%
  {\pgfpointanchor{p1}{center}}
\let\myendresult\pgfmathresult

\fill [fill=blue!50,draw=blue,thin,opacity=0.5] (p1) -- (pext) arc [start angle=\myendresult,delta angle=-40,radius=\radius] -- cycle;
\fill [fill=blue!50,draw=blue,thin,opacity=0.5] (p1) -- (pext) arc [start angle=\myendresult,delta angle=25,radius=\radius] -- cycle;

\end{tikzpicture}

\end{document}

some stupid plot

5
  • That looks awesome, Thanks for the hint regarding the doubled computation of the prolonged point. Shows that I didn't know, I already created that point by $(p1.center)!-\radius!(p0.center)$. Actually, there's no way to do the drawing right after each addplot command has been processed? Tried to do this using \pgfplotsextra
    – goeck
    Aug 17, 2014 at 12:06
  • @goeck - My understanding is that \pgfplotsextra simply stops the tikz parser, where as the \addplots don't actually do anything until \end{axis} starts the process. BTW, 50 x units and 50 y units are very slightly different (280 vs 350 over 10 cm). Aug 17, 2014 at 13:59
  • @JohnKormylo Ah nice catch. I should have known. You can instead put the contents of the \pgfplotsextra as an option to axis via after end axis/.code={...contents...} if you wish to stay within the axis environment.
    – percusse
    Aug 17, 2014 at 14:02
  • I have been in holidays, so no word for days here. After adding some code that was posted by @JohnKormylo and restructuring everything according to my needs I am happy with the solution. I added plotting in the background of the arcs, also I now have all lengths correct - I guess. Also I was able to get rid of the double painting of transparent areas and lines using the transparency group feature of scopes. Thanks for alle the help and support. i.stack.imgur.com/ocMVk.png i.stack.imgur.com/OwAmp.png
    – goeck
    Aug 26, 2014 at 17:47
  • Here is the code of my final solution: gist.github.com/goeck/418d3a3c3f11cec17846#file-arcs
    – goeck
    Aug 26, 2014 at 17:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .