2

In the of the following code, I store in-center to the point I by command \incenter(A,B,C)(I).

I want to store in-radius to a real number \inr by command \inradius(A,B,C)(inr), then later I could use \draw (I) circle(\inr);. However, it does not work.

Anyone can help?

enter image description here

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
% a point on the in-bisector (PGF manual, page 1008)    
\def\bisector(#1,#2,#3)(#4){
\path let 
\p1=($(#2)-(#1)$),\p2=($(#2)-(#3)$), 
\n1={veclen(\x1,\y1)},\n2={veclen(\x2,\y2)}
in ($(#1)!scalar(\n1/(\n1+\n2))!(#3)$) coordinate (#4);
}

% In-center
\def\incenter(#1,#2,#3)(#4){
\bisector(#1,#2,#3)(p2)
\bisector(#1,#3,#2)(p3)
\coordinate (#4) at (intersection of #2--p2 and #3--p3);
}

% In-radius (expression is from marmot's suggestion)
\def\inradius(#1,#2,#3)(#4){
\path let 
\p1=($(#2)-(#1)$), 
\p2=($(#3)-(#1)$),
\p3=($(#2)-(#3)$),
\n1={.5* 
(veclen(\x1,\y1)+veclen(\x2,\y2)+veclen(\x3,\y3))},
\n2={sqrt(((\n1-veclen(\x1,\y1))/\n1))*sqrt((\n1- 
veclen(\x2,\y2))*(\n1-veclen(\x3,\y3)))},
in 
\pgfextra{\xdef\inr{\n2}};
%\pgfmathsetmacro{#4}{\n2}; % <<<I want to store to #4 
}

\begin{tikzpicture}
\path
(-1,0) coordinate (B)
(4,0) coordinate (C)
(0,3.5) coordinate (A);

\bisector(C,A,B)(M)
\bisector(A,B,C)(N)
\bisector(B,C,A)(P)
\incenter(A,B,C)(I)
\inradius(A,B,C)(inr)

\draw[blue] (A)--(M) (B)--(N) (C)--(P); 
\draw (A)--(B)--(C)--cycle;
\fill[red] (I) circle(1.5pt);
\draw[red] (I) circle(\inr);

\path 
(A) node[above]{A} 
(B) node[below left]{B}
(C) node[below right]{C}
(M) node[below]{M}
(N) node[above right]{N}
(P) node[above left]{P};
\end{tikzpicture}
\end{document}
4

You only need

\xdef#4{\n2}

or

\expandafter\xdef\csname #4\endcsname{\n2}

depending on if you want to use

\inradius(A,B,C)(\inr)

or

\inradius(A,B,C)(inr)

Full codes:

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
% a point on the in-bisector (PGF manual, page 1008)    
\def\bisector(#1,#2,#3)(#4){
\path let 
\p1=($(#2)-(#1)$),\p2=($(#2)-(#3)$), 
\n1={veclen(\x1,\y1)},\n2={veclen(\x2,\y2)}
in ($(#1)!scalar(\n1/(\n1+\n2))!(#3)$) coordinate (#4);
}

% In-center
\def\incenter(#1,#2,#3)(#4){
\bisector(#1,#2,#3)(p2)
\bisector(#1,#3,#2)(p3)
\coordinate (#4) at (intersection of #2--p2 and #3--p3);
}

% In-radius (expression is from marmot's suggestion)
\def\inradius(#1,#2,#3)(#4){
\path let 
\p1=($(#2)-(#1)$), 
\p2=($(#3)-(#1)$),
\p3=($(#2)-(#3)$),
\n1={.5* 
(veclen(\x1,\y1)+veclen(\x2,\y2)+veclen(\x3,\y3))},
\n2={sqrt(((\n1-veclen(\x1,\y1))/\n1))*sqrt((\n1- 
veclen(\x2,\y2))*(\n1-veclen(\x3,\y3)))},
in 
\pgfextra{\xdef#4{\n2}};
%\pgfmathsetmacro{#4}{\n2}; % <<<I want to store to #4 
}

\begin{tikzpicture}
\path
(-1,0) coordinate (B)
(4,0) coordinate (C)
(0,3.5) coordinate (A);

\bisector(C,A,B)(M)
\bisector(A,B,C)(N)
\bisector(B,C,A)(P)
\incenter(A,B,C)(I)
\inradius(A,B,C)(\inr)

\draw[blue] (A)--(M) (B)--(N) (C)--(P); 
\draw (A)--(B)--(C)--cycle;
\fill[red] (I) circle(1.5pt);
\draw[blue,dashed] (I) circle(\inr);

\path 
(A) node[above]{A} 
(B) node[below left]{B}
(C) node[below right]{C}
(M) node[below]{M}
(N) node[above right]{N}
(P) node[above left]{P};
\end{tikzpicture}
\end{document}

enter image description here

Or if you do not want to add a backslash

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
% a point on the in-bisector (PGF manual, page 1008)    
\def\bisector(#1,#2,#3)(#4){
\path let 
\p1=($(#2)-(#1)$),\p2=($(#2)-(#3)$), 
\n1={veclen(\x1,\y1)},\n2={veclen(\x2,\y2)}
in ($(#1)!scalar(\n1/(\n1+\n2))!(#3)$) coordinate (#4);
}

% In-center
\def\incenter(#1,#2,#3)(#4){
\bisector(#1,#2,#3)(p2)
\bisector(#1,#3,#2)(p3)
\coordinate (#4) at (intersection of #2--p2 and #3--p3);
}

% In-radius (expression is from marmot's suggestion)
\def\inradius(#1,#2,#3)(#4){
\path let 
\p1=($(#2)-(#1)$), 
\p2=($(#3)-(#1)$),
\p3=($(#2)-(#3)$),
\n1={.5* 
(veclen(\x1,\y1)+veclen(\x2,\y2)+veclen(\x3,\y3))},
\n2={sqrt(((\n1-veclen(\x1,\y1))/\n1))*sqrt((\n1- 
veclen(\x2,\y2))*(\n1-veclen(\x3,\y3)))},
in 
\pgfextra{\expandafter\xdef\csname #4\endcsname{\n2}};
%\pgfmathsetmacro{#4}{\n2}; % <<<I want to store to #4 
}

\begin{tikzpicture}
\path
(-1,0) coordinate (B)
(4,0) coordinate (C)
(0,3.5) coordinate (A);

\bisector(C,A,B)(M)
\bisector(A,B,C)(N)
\bisector(B,C,A)(P)
\incenter(A,B,C)(I)
\inradius(A,B,C)(inr)

\draw[blue] (A)--(M) (B)--(N) (C)--(P); 
\draw (A)--(B)--(C)--cycle;
\fill[red] (I) circle(1.5pt);
\draw[blue,dashed] (I) circle(\inr);

\path 
(A) node[above]{A} 
(B) node[below left]{B}
(C) node[below right]{C}
(M) node[below]{M}
(N) node[above right]{N}
(P) node[above left]{P};
\end{tikzpicture}
\end{document}
  • 1
    You are a dictionary on Tex - TikZ! thanks! – Black Mild Jun 19 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.