I'd suspect some version trouble, too
Code: Select all
\listfiles
\documentclass[10pt,titlepage,leqno]{article}
\usepackage{tikz}
\usepackage{bm}% (rais) bold math
\usetikzlibrary{calc,through,backgrounds,patterns}
\newif\ifmydebug % (rais) a switch for debug info
\mydebugtrue% (rais) set to false to suppress debug info in the output
\newcommand*\dbginf[1]{% (rais) just a small macro to output debug info...or suppress it
\ifmydebug
(#1)%
\fi
}
% \deflen macro is used by the macro \mgtrianglesidelength below
\newcommand{\deflen}[2]{%
\expandafter\newlength\csname #1\endcsname
\expandafter\setlength\csname #1\endcsname{#2}%
}
% \getcoords macro get coordinates x and y from point A = (x,y) defined by \coordinate (A) at (x,y);
% the code for \getcoords was communicated to me through the latex forum online
% (credit to Stefan Kottwitz/Andrew Stacey here)
% need this since I am running PGF 2.0
\makeatletter
\newcommand{\getcoords}[3]{%
\tikz@scan@one@point\pgfutil@firstofone(#1)\relax
\edef#2{\the\pgf@x}%
\edef#3{\the\pgf@y}%
}
\makeatother
% \mgtrianglesidelength macro calculates the lengths of the sides of a given triangle ABC
% from the coordinates of its corners
% I don't have tikz-2d
%---------------------------------------------------------------------------------------
\def\mgtrianglesidelength[#1,#2,#3]{%
\getcoords{#1}{\xf}{\yf};
\getcoords{#2}{\xs}{\ys};
\pgfmathparse{veclen(\xs-\xf,\ys-\yf)};
\deflen{#3}{\pgfmathresult pt}
}
%---------------------------------------------------------------------------------------
% PURPOSE OF THE FOLLOWING:
% GIVEN THE TRIANGLE ABC, FROM ITS CORNES DEFINED BY THEIR COORDINATES, DRAW THE
% INCIRCLE OF ABC
%---------------------------------------------------------------------------------------
\begin{document}
\newcommand{\scalefactor}{2.0}
\begin{figure} [htbp]
\centering
\begin{tikzpicture}[scale=\scalefactor]
% define the triangle to work with
% easy example, but the set up should work for a general non-degenerate triangle
\coordinate [label=below:$\bm{A}$] (A) at (0,0);% (rais) \bf is considered bad practice for about twenty years, now
\coordinate [label=below:$\bm{B}$] (B) at (2,0);
\coordinate [label=above:$\bm{C}$] (C) at (2,3);
\fill[yellow] (A)--(B)--(C)--cycle;
% \draw[red,ultra thick] (A)--(B)--(C)--cycle;
% calculate the side lengths of the given triangle ABC
\mgtrianglesidelength[B,C,la];
\mgtrianglesidelength[A,C,lb];
\mgtrianglesidelength[A,B,lc];
% the following debug output does not work, but the side lengths have been checked to be correct
\draw[red,ultra thick]
(A)--(B) node[below, midway, sloped, black]{$c$ \dbginf{\the\lc}}
--(C) node[below, midway, sloped, black]{$a$ \dbginf{\the\la}}
--cycle node[above, midway, sloped, black]{$b$ \dbginf{\the\lb}};
% \path node at (1,1) {\la,\lb,\lc};%does not work properly!!?? ANY COMMENT WHY THE DEBUG GENERATES AN ERROR?
% (rais) within \mgtrianglesidelength, you're using \deflen for defining the third parameter (\la, \lb, and \lc in the three calls above), which defines them as length registers. Use \the if you want to know what's in a length register (see my \dbginf above)
%
% finally, generate and draw the inscribed circle of the triangle ABC
% the coordinates of the incenter I = (xI,yI) and radius r of the inscribed circle are
% (1.30278,0.697224) and 0.697224 (in cm), resp., as calculated explicitly by Mathematica
% due to the special triangle ABC chosen (AB horizontal), we have r = yI
% calculate I = (xI,yI) and r, using PGF
\pgfmathsetmacro{\aA}{acos((\la/100*\la/100-\lb/100*\lb/100-\lc/100*\lc/100)/(-2*\lb/100*\lc/100))};
\pgfmathsetmacro{\aA}{180*(\aA<0)+\aA};%mod(\aA,180) etc. does not work if the angle is obstuse
% calculate I = (\xI,\yI) and r
\getcoords{A}{\xA}{\yA};
\getcoords{B}{\xB}{\yB};
\getcoords{C}{\xC}{\yC};
\pgfmathsetmacro{\S}{\la+\lb+\lc};
\pgfmathsetmacro{\xI}{(\la*\xA+\lb*\xB+\lc*\xC)/\S};
\pgfmathsetmacro{\yI}{(\la*\yA+\lb*\yB+\lc*\yC)/\S};
\pgfmathsetmacro{\r}{\lb*\lc*sin(\aA)/\S};
%-----------------------------------------------------------------------------------------
% draw circle(s)
%-----------------------------------------------------------------------------------------
% correct inscribed circle defined by I and r from mathematica above
\draw[red,very thick] (1.30278,0.697224) circle (0.697224);
%-----------------------------------------------------------------------------------------
% inscribed circle as defined by pgf/tikz above
%-----------------------------------------------------------------------------------------
% \draw[blue,thick] (\xI,\yI) circle (\r); %NOT CORRECT!
% (rais) yes, well, \xI, \yI, and \r appear to be based on pt, but unitless; \draw (a.s.o.), however, use cm by default, their input is usually unitless, as well...but you can give them a unit:
\draw[blue,thick] (\xI pt,\yI pt) circle (\r pt);% (rais) note the "pt"
% (rais) for me, the following isn't necessary
\pgfmathsetmacro{\cmpt}{72.27/2.54};%convert from cm to pt; (rais) 2.54 cm equal 72.27 pt
\pgfmathsetmacro{\ptcm}{1/\cmpt};%convert from pt to cm
\pgfmathsetmacro{\xI}{\xI*\ptcm};
\pgfmathsetmacro{\yI}{\yI*\ptcm};
\pgfmathsetmacro{\r}{\r*\ptcm};
\draw[cyan,thin] (\xI,\yI) circle (\r); %(rais) works for me
% (rais) skipped the multiplication by 10 because I really don't see a need for it
%----------------------------------------------------------------------------------
\end{tikzpicture}
\end{figure}
\end{document}
creates three incircles with the same dimensions (and points of origin, just different thicknesses/colors) for me.
My file list (compare with your log file, it's close to the end, if
\listfiles
was given)
Code: Select all
*File List*
article.cls 2014/09/29 v1.4h Standard LaTeX document class
leqno.clo 2015/03/31 v1.1i Standard LaTeX option (left equation numbers)
size10.clo 2014/09/29 v1.4h Standard LaTeX file (size option)
tikz.sty 2015/08/07 v3.0.1a (rcs-revision 1.151)
pgf.sty 2015/08/07 v3.0.1a (rcs-revision 1.15)
pgfrcs.sty 2015/08/07 v3.0.1a (rcs-revision 1.31)
everyshi.sty 2001/05/15 v3.00 EveryShipout Package (MS)
pgfrcs.code.tex
pgfcore.sty 2010/04/11 v3.0.1a (rcs-revision 1.7)
graphicx.sty 2014/10/28 v1.0g Enhanced LaTeX Graphics (DPC,SPQR)
keyval.sty 2014/10/28 v1.15 key=value parser (DPC)
graphics.sty 2016/07/10 v1.0t Standard LaTeX Graphics (DPC,SPQR)
trig.sty 2016/01/03 v1.10 sin cos tan (DPC)
graphics.cfg 2016/06/04 v1.11 sample graphics configuration
pdftex.def 2016/07/10 v0.06j Graphics/color for pdfTeX
infwarerr.sty 2016/05/16 v1.4 Providing info/warning/error messages (HO)
ltxcmds.sty 2016/05/16 v1.23 LaTeX kernel commands for general use (HO)
pgfsys.sty 2014/07/09 v3.0.1a (rcs-revision 1.48)
pgfsys.code.tex
pgfsyssoftpath.code.tex 2013/09/09 (rcs-revision 1.9)
pgfsysprotocol.code.tex 2006/10/16 (rcs-revision 1.4)
xcolor.sty 2016/05/11 v2.12 LaTeX color extensions (UK)
color.cfg 2016/01/02 v1.6 sample color configuration
pgfcore.code.tex
pgfcomp-version-0-65.sty 2007/07/03 v3.0.1a (rcs-revision 1.7)
pgfcomp-version-1-18.sty 2007/07/23 v3.0.1a (rcs-revision 1.1)
pgffor.sty 2013/12/13 v3.0.1a (rcs-revision 1.25)
pgfkeys.sty
pgfkeys.code.tex
pgfmath.sty
pgfmath.code.tex
pgffor.code.tex
tikz.code.tex
bm.sty 2016/07/07 v1.2b Bold Symbol Support (DPC/FMi)
supp-pdf.mkii
pdftexcmds.sty 2016/05/21 v0.22 Utility functions of pdfTeX for LuaTeX (HO)
ifluatex.sty 2016/05/16 v1.4 Provides the ifluatex switch (HO)
ifpdf.sty 2016/05/14 v3.1 Provides the ifpdf switch
epstopdf-base.sty 2016/05/15 v2.6 Base part for package epstopdf
grfext.sty 2016/05/16 v1.2 Manage graphics extensions (HO)
kvdefinekeys.sty 2016/05/16 v1.4 Define keys (HO)
kvoptions.sty 2016/05/16 v3.12 Key value format for package options (HO)
kvsetkeys.sty 2016/05/16 v1.17 Key value parser (HO)
etexcmds.sty 2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO)
epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live
***********
KR
Rainer