tkz-euclide,定义 tikzpicture 之外的点

tkz-euclide,定义 tikzpicture 之外的点

是否可以在 tikzpicture 环境之外定义 tkz-euclide 中的点?

例如,我希望在初等几何中进行类似这样的练习:

Exercise:

Consider the triangle $\Delta$ defined by the points \definePoint{A,2,3}, 
\definePoint{B,10,3} and \definePoint{C,-1,4}. 
Draw the inscribed circle and the circumscribed circle of this triangle.

Solution:

\begin{tikzpicture}
% The triangle
%A,B,C are defined in the exercise above
\tkzDrawSegments(A,B B,C C,A)

% circumcircle
\tkzCircumCenter(A,B,C)\tkzGetPoint{G}
\tkzDrawPoint(G)
\tkzDrawCircle(G,A)

% incircle
\tkzDefCircle[in](A,B,C)\tkzGetPoint{I}\tkzGetLength{rIN}
\tkzDrawPoint(I)
\tkzDrawCircle[R](I,\rIN pt)

\tkzLabelPoints[below](B)
\tkzLabelPoints[below left](C)
\tkzLabelPoints[above left](A,I,G)
\end{tikzpicture}

重点是,如果我修改问题中的点 A、B、C 的坐标,那么解决方案中的点也应该修改。

答案1

我不知道有任何官方方法可以做到这一点。TikZ 似乎会记住图片之间节点的位置,但我认为这主要是节点存储方式的意外副作用,而不是任何官方支持的方式。无论如何,你可以写

\tikz \tkzDefPoint(1,2){A};

并且 A 的位置将在下一张图片中为人所知(或者从技术上讲直到定义了名为 A 的新节点)。

最好将点定义存储在钩子中,并将它们添加到 的开头tikzpicture,如以下代码所示。这样,就不必依赖未记录的功能,并且可以使用label的选项\tkzDefPoint

\documentclass{minimal}
\usepackage{tkz-euclide}

\makeatletter
% Define a point for use in the next TkZ drawing.
%
% Takes 2 mandatory and one optional argument:
%  * The optional argument is passed as optional argument to \tkzDefPoint.
%  * The first mandatory argument is the name of the point, e.g. “A”.
%  * The second mandatory argument is the coordinates of the point (without parenthesis).
%
% The macro also adds $name = (coordinates)$ to the text.
%
% To actually add the points to a tikzpicture, you need to call \definedPoints
% at the start of the tikzpicture.
\newcommand*\definePoint[3][]{%
    \g@addto@macro\tsx@pointhook{\tkzDefPoint[#1](#3){#2}}%
    $#2=(#3)$%
}

% hook to store the points until they are used
\def\tsx@pointhook{}

% Print anything in the hook and clear in afterwards.
\newcommand\definedPoints{%
    \tsx@pointhook%
    \gdef\tsx@pointhook{}%
}
\makeatother

\begin{document}
Consider the triangle $\Delta$ defined by the points \definePoint[label=above:$A$]{A}{2,3}, 
\definePoint{B}{8,3} and \definePoint{C}{-1,-1}. 

\begin{tikzpicture}
    % The triangle
    % A,B,C are defined in the exercise above
    \definedPoints
    \tkzDrawSegments(A,B B,C C,A)
\end{tikzpicture}
\end{document}

相关内容