5

Consider the following MWE:

\documentclass[border=5pt,tikz]{standalone}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}[join=bevel]
   \draw (0,0) coordinate (B) -- (6,0) coordinate (C)  
        -- (6,4.5) coordinate (A) -- cycle;
   \coordinate (F) at ($(A)!(C)!(B)$);
   \draw (C) -- (B) -- (0,8) coordinate (D)  -- cycle;
   \draw[fill=gray] (D) -- (A) -- (F) -- cycle;
\end{tikzpicture}

\end{document}

It yields enter image description here

However, the corner of the gray triangle should be exactly on the line from the top left to the lower right corner. (This can be easily verified with GeoGebra or by calculation.)

Why does this happen?

5

As pointed out by Mark Wibrow in this answer the definition of \pgfpointnormalised can be corrected to obtain better precision.

\documentclass[border=5pt,tikz]{standalone}

\usepackage{tikz}
\usetikzlibrary{calc, spy}

% use the Mark Wibrow's correction
\makeatletter
\def\pgfpointnormalised#1{%
  \pgf@process{#1}%
  \pgfmathatantwo{\the\pgf@y}{\the\pgf@x}%
  \let\pgf@tmp=\pgfmathresult%
  \pgfmathcos@{\pgf@tmp}\pgf@x=\pgfmathresult pt\relax%
  \pgfmathsin@{\pgf@tmp}\pgf@y=\pgfmathresult pt\relax%
}
\makeatother

\begin{document}

\begin{tikzpicture}[join=bevel, spy using outlines={circle, magnification=7, size=17mm, connect spies}]
   \draw (0,0) coordinate (B) -- (6,0) coordinate (C)
        -- (6,4.5) coordinate (A) -- cycle;
   \coordinate (F) at ($(A)!(C)!(B)$);
   \draw (C) -- (B) -- (0,8) coordinate (D)  -- cycle;
   \draw[fill=gray] (D) -- (A) -- (F) -- cycle;

   \spy[red] on (F) in node at (1,2);
\end{tikzpicture}

\end{document}

enter image description here

Note : This is a copy of this answer.

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.