2

The following declaration

\tikzset{
      ncbar/.style={
        to path={%
        ($(\tikztostart)!#1!90:(\tikztotarget)$)
        -- ($(\tikztotarget)!#1!270:(\tikztostart)$)\tikztonodes}},
      ncbar/.default=0.5cm,
    }

does not pick up the \tikztonodes command, since the two nodes

\draw[<->] (A) to[ncbar=0.2](C) node[midway, sloped, above] {\small $30dm$}; 
\draw[<->] (C) to[ncbar=0.33](B) node[midway, sloped, above] {\small $40dm$}; 

do not appear in the picture:

tikz output

Code inspired by

\documentclass{article}
\usepackage{amsmath}
\usepackage{pgf,tikz,pgfplots, tikz-cd}
\usetikzlibrary{arrows, intersections,decorations.markings, patterns, calc}
\usepackage{tkz-euclide}
\usepackage{calc}

\tikzset{ ncbar/.style={ to path={% ($(\tikztostart)!#1!90:(\tikztotarget)$) -- ($(\tikztotarget)!#1!270:(\tikztostart)$)\tikztonodes}}, ncbar/.default=0.5cm, }

\begin{document} \begin{tikzpicture}[remember picture] % A path that follows the edges of the current page \tikzstyle{reverseclip}=[insert path={(current page.north east) -- (current page.south east) -- (current page.south west) -- (current page.north west) -- (current page.north east)} ] \coordinate[] (A) at (-1,0); \coordinate[] (B) at (1,0); \coordinate[] (C) at (-0.5,0.86602); \draw (A) -- (B) -- (C) -- cycle; \draw (B) arc[start angle=0, end angle=180, radius=1];

\begin{pgfinterruptboundingbox} \clip (A) -- (B) -- (C) -- cycle [reverseclip]; \end{pgfinterruptboundingbox}

\fill[fill=green!20!white] (B) arc[start angle=0, end angle=180, radius=1]; \draw[<->] (A)+(0,-.2)--($(B)+(0,-.2)$) node[midway, below] {\small $50dm$}; \draw[<->] (A) toncbar=0.2 node[midway, sloped, above] {\small $30dm$}; \draw[<->] (C) toncbar=0.33 node[midway, sloped, above] {\small $40dm$}; \end{tikzpicture} \end{document}

Nre
  • 222
  • The reason that your nodes aren't being collected is because they are specified after the target coordinate of the to path. I have a suspicion that they are being placed inside the clipped area, if you comment out the clip what happens? To qualify for \tikztonodes then they need to be declared between the to and the target node. – Andrew Stacey Apr 11 '22 at 08:41

2 Answers2

3

Sorry, I was not able to figured out the most part of your code. If the problem is reproduce showed image, than the MWE, which do this, can be (much simpler):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, 
                calc,
                decorations.markings, 
                quotes}
\usepackage{siunitx}

\tikzset{ every edge/.style = {draw, Straight Barb-Straight Barb}, every edge quotes/.style = {auto, font=\footnotesize, sloped} }

\begin{document} \begin{tikzpicture} \coordinate (A) at (-1,0); \coordinate (B) at (1,0); \coordinate (C) at (-0.5,0.86602); % \draw[fill=green] (B) arc (0:180:1); \draw[fill=white] (A) -- (B) -- (C) -- cycle; % \draw ([yshift=-2mm] A) edge["\qty{50}{\deci\metre}" below] ([yshift=-2mm] B) ($(B)!7mm!-90:(C)$) edge["\qty{40}{\deci\metre}"] ($(C)!7mm!+90:(B)$) ($(A)!3mm!90:(C)$) edge["\qty{30}{\deci\metre}"] ($(C)!3mm!-90:(A)$) ; \end{tikzpicture} \end{document}

enter image description here

Addendum:

What is wrong with your code?

  • it is unnecessary complicated, so it easy to lost in it
  • code for arrows with labels is wrong. Instead of used
\draw[<->] (A) to[ncbar=0.2](C) node[midway, sloped, above] {\small $30dm$}; 
\draw[<->] (C) to[ncbar=0.33](B) node[midway, sloped, above] {\small $40dm$}; 

it should be:

\draw[<->]  (A) 
        to[ncbar=0.3] node[font=\small, sloped, above] {$30dm$}
            (C);
\draw[<->]  (C) 
        to[ncbar=0.4] node[font=\small, sloped, above] {$30dm$}
            (B);
  • After cleanup your document example, your document example can be:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows, 
                calc,
                decorations.markings, 
                intersections,
                }
\usepackage{tkz-euclide}
\usepackage{calc}

\tikzset{ ncbar/.style={ to path={% ($(\tikztostart)!#1!90:(\tikztotarget)$) -- ($(\tikztotarget)!#1!270:(\tikztostart)$)\tikztonodes}}, ncbar/.default=0.5cm, }

\begin{document} \begin{tikzpicture} \coordinate[] (A) at (-1,0); \coordinate[] (B) at (1,0); \coordinate[] (C) at (-0.5,0.86602); \draw[fill=green!20!white] (B) arc[start angle=0, end angle=180, radius=1]; \draw[fill=white] (A) -- (B) -- (C) -- cycle; % \draw[<->] ($(A)+(0,-.2)$) --
node[font=\small, below] {$50dm$} ($(B)+(0,-.2)$); \draw[<->] (A) to[ncbar=0.3] node[font=\small, sloped, above] {$30dm$} (C); \draw[<->] (C) to[ncbar=0.4] node[font=\small, sloped, above] {$30dm$} (B); \end{tikzpicture} \end{document}

and gives the following result:

enter image description here

However, the same result can be obtained with your code too if in it is considered suggested changes. Using it you need at least two compilation to get correct result.

Comparison above MWE (Minimal Working Example) and your code clearly show, that the most of code in your document example are unnecessary and therefore can be consider as clutter and should be omitted.

Zarko
  • 296,517
  • Thanks, but the goal would be to indicate what is not working in my code, not to simply reproduce the picture. – Nre Apr 11 '22 at 05:06
  • 1
    @Nre, your code not working because it is unnecessary complicated and for most of part is not clear what is its purpose. You are use of arrows with labels is wrong. See addendum to answer (will appear ASAP) – Zarko Apr 11 '22 at 07:02
  • Ok, thank you for the feedback, will have a look at your code then. – Nre Apr 11 '22 at 07:25
0

Another solution with TikZ, you can use even odd rule for more concise code.

enter image description here

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\def\r{5/2}
\pgfmathsetmacro{\t}{atan(3/4)}
\path
(-\r,0) coordinate (A)      
(\r,0)  coordinate (B)
({180-2*\t}:\r) coordinate (C)
;
\tikzset{n/.style={midway,sloped,fill=white,text=black}}
\draw[|<->|,gray] ($(B)!13mm!-90:(C)$)--($(C)!13mm!90:(B)$)
node[n]{$40\,\mathrm{dm}$};
\draw[|<->|,gray] ($(A)!9mm!90:(C)$)--($(C)!9mm!-90:(A)$)
node[n]{$30\,\mathrm{dm}$};
\draw[|<->|,gray] ([yshift=-5mm]A)--([yshift=-5mm]B)
node[n]{$50\,\mathrm{dm}$};

\draw[fill=green,even odd rule] (B) arc(0:180:\r)--cycle (A)--(B)--(C)--cycle; \end{tikzpicture} \end{document}


A try with Asymptote. It seems that siunitx does not work on http://asymptote.ualberta.ca/

enter image description here

//usepackage("siunitx");  // It seems does not work on http://asymptote.ualberta.ca/
unitsize(1cm);
real r=5/2;
real t=aTan(3/4);      // in degrees
pair A=(-r,0), B=(r,0), C=r*dir(180-2t);
path tri=A--B--C--cycle;
path cir=arc((0,0),r,0,180)--cycle;

transform s=shift(0,-.4); draw(Label("$50 ,\mathrm{dm}$",black,Fill(white),align=(0,0)),sA--sB,gray,Arrows(TeXHead),Bars);

pair Bt=B+1.3unit(rotate(-90,B)(C-B)); //dot(Bt); pair Ct=C+1.3unit(rotate(90,C)(B-C)); //dot(Ct); draw(Label("$40 ,\mathrm{dm}$",black,Rotate(Bt-Ct),Fill(white),align=(0,0)),Bt--Ct,gray,Arrows(TeXHead),Bars);

pair As=A+.9unit(rotate(90,A)(C-A)); //dot(Bt); pair Cs=C+.9unit(rotate(-90,C)(A-C)); //dot(Ct); draw(Label("$30 ,\mathrm{dm}$",black,Rotate(Cs-As),Fill(white),align=(0,0)),Cs--As,gray,Arrows(TeXHead),Bars);

filldraw(tri^^cir,evenodd+yellow);

shipout(bbox(5mm,invisible));

Black Mild
  • 17,569