![将点从 Tikz 复制到 Tkz](https://linux22.com/image/409365/%E5%B0%86%E7%82%B9%E4%BB%8E%20Tikz%20%E5%A4%8D%E5%88%B6%E5%88%B0%20Tkz.png)
我只是想知道从 TikZ 到 Tkz 的方法,因为反向方法非常简单。
\documentclass[tikz]{standalone}
\usepackage{tkz-euclide}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\tkzDefPoint(1,1){A}
\node at (A){A};
\draw[name path=line1] (A) -- (4,2);
\draw[name path=line2] (2,0) -- (2,4);
\fill[name intersections={of=line1 and line2, by={B}}] (B) circle (2pt);
% \tkzDefPoint(B){CopyOfB} % that's not right, isn't it?
% \node at (CopyOfB){B};
\end{tikzpicture}
\end{document}
提前谢谢
答案1
使用内部宏是可能的tkz-euclide
(新文档 3.05 杂项工具的第 128 页)
\documentclass[tikz]{standalone}
\usepackage{tkz-euclide}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\tkzDefPoint(1,1){A}
\node at (A){A};
\draw[name path=line1] (A) -- (4,2);
\draw[name path=line2] (2,0) -- (2,4);
\fill[name intersections={of=line1 and line2, by={B}}] (B) circle (2pt);
\tkzGetPointCoord(B){V}
\tkzDefPoint(\Vx,\Vy){copyB}
\tkzDrawPoint[red](copyB)
\end{tikzpicture}
\end{document}
答案2
您始终可以提取点的坐标并使用它们。这可用于定义“复制” Ti钾Z 指向 tkz。(请注意,此版本的宏假定您没有自定义坐标,即您没有重新定义x
。y
)
\documentclass[tikz]{standalone}
\usepackage{tkz-euclide}
\usetikzlibrary{intersections}
\newcommand{\CopyPointToTkz}[2]{\path (#1);
\pgfgetlastxy{\macrox}{\macroy}
\pgfmathsetmacro{\macroxcm}{\macrox/1cm}
\pgfmathsetmacro{\macroycm}{\macroy/1cm}
\tkzDefPoint(\macroxcm,\macroycm){#2}
}
\begin{document}
\begin{tikzpicture}
\tkzDefPoint(1,1){A}
\node at (A){A};
\draw[name path=line1] (A) -- (4,2);
\draw[name path=line2] (2,0) -- (2,4);
\fill[name intersections={of=line1 and line2, by={B}}] (B) circle (2pt);
\CopyPointToTkz{B}{CopyOfB}
\node at (CopyOfB){B};
\end{tikzpicture}
\end{document}
如果您想要允许任意重新定义坐标系,那么您需要做得更复杂一些。
\documentclass[tikz]{standalone}
\usepackage{tkz-euclide}
\usetikzlibrary{intersections}
\makeatletter
\newcommand{\CopyPointToTkz}[2]{\path (#1);
\pgfgetlastxy{\macrox}{\macroy}
\pgfmathsetmacro{\macroxcm}{\macrox/1cm}
\pgfmathsetmacro{\macroycm}{\macroy/1cm}
\pgfmathsetmacro{\mya}{\pgf@xx/1cm}
\pgfmathsetmacro{\myb}{\pgf@yx/1cm}
\pgfmathsetmacro{\myc}{\pgf@xy/1cm}
\pgfmathsetmacro{\myd}{\pgf@yy/1cm}
\pgfmathsetmacro{\mydet}{\mya*\myd-\myb*\myc}
\pgfmathsetmacro{\myxx}{\myd/\mydet}
\pgfmathsetmacro{\myxy}{-\myc/\mydet}
\pgfmathsetmacro{\myyx}{-\myb/\mydet}
\pgfmathsetmacro{\myyy}{\mya/\mydet}
\tkzDefPoint(\macroxcm*\myxx+\macroycm*\myyx,\macroxcm*\myxy+\macroycm*\myyy){#2}
}
\makeatother
\begin{document}
\begin{tikzpicture}[x=2cm]
\tkzDefPoint(1,1){A}
\node at (A){A};
\draw[name path=line1] (A) -- (4,2);
\draw[name path=line2] (2,0) -- (2,4);
\fill[name intersections={of=line1 and line2, by={B}}] (B) circle (2pt);
\CopyPointToTkz{B}{CopyOfB}
\node at (CopyOfB){B};
\end{tikzpicture}
\end{document}