我使用 \tikzdeclarecoordinatesystem 创建了一个新的坐标系。当 scale=1 时编译为 true,否则编译为 false。为什么?你能帮助我吗?非常感谢。这是我的代码。
\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{calc, intersections}
\makeatletter
\tikzset{/tikz/giaodiemthangtron cs/.cd,
thang line initial coordinate/.store in=\tikz@giaodiem@onA,
thang line final coordinate/.store in=\tikz@giaodiem@onB,
tron line initial coordinate/.store in=\tikz@giaodiem@andC,
tron line final coordinate/.store in=\tikz@giaodiem@andD,
thang/.style args={#1--#2}{
thang line initial coordinate=#1,
thang line final coordinate=#2,
},
tron/.style args={#1--#2}{
tron line initial coordinate=#1,
tron line final coordinate=#2,
},
point/.store in=\point,
}
%
\tikzdeclarecoordinatesystem{giaodiemthangtron}{
\tikzset{/tikz/giaodiemthangtron cs/.cd,#1}
\pgfextra
{
\pgfextract@process\pgf@giaodiem@onA{\tikz@scan@one@point\pgfutil@firstofone(\tikz@giaodiem@onA)\relax}%
\pgfextract@process\pgf@giaodiem@onB{\tikz@scan@one@point\pgfutil@firstofone(\tikz@giaodiem@onB)\relax}%
%
\pgfextract@process\pgf@giaodiem@andC{\tikz@scan@one@point\pgfutil@firstofone(\tikz@giaodiem@andC)\relax}%
\pgfextract@process\pgf@giaodiem@andD{\tikz@scan@one@point\pgfutil@firstofone(\tikz@giaodiem@andD)\relax}%
%rCD
\pgfpointdiff{\pgf@giaodiem@andC}{\pgf@giaodiem@andD}%
\pgfmathveclen@{\pgfmath@tonumber\pgf@x}{\pgfmath@tonumber\pgf@y}%
\edef\pgf@bankinhCD{\pgfmathresult pt}
% get intersections
\pgfintersectionofpaths
{%AB
\pgfpathmoveto{\pgf@giaodiem@onA}
\pgfpathlineto{\pgf@giaodiem@onB}
%
%\pgfgetpath\temppath
%\pgfsetpath\temppath
}
{%circle
\pgfpathcircle{\pgf@giaodiem@andC}{\pgf@bankinhCD}
}
\pgfextract@process\pgf@giao{
\pgfpointintersectionsolution{\point}
}
\pgfcoordinate{giaodiem}{\pgf@giao}%
}
\tikz@scan@one@point\pgfutil@firstofone(giaodiem)%
\relax
}
\makeatother
\begin{document}
\begin{tikzpicture}[font=\small, scale=1]
\path(0,0)coordinate(A)(5,1)coordinate(B) (2,1)coordinate(C) (1,2)coordinate(D)
(giaodiemthangtron cs: thang=A--B, tron=C--D, point=1) coordinate(M)
(giaodiemthangtron cs: thang=A--B, tron=C--D, point=2) coordinate(N);
\draw[blue] let \p1 =($(C)-(D)$), \n1 = {veclen(\x1,\y1)} in (C) circle (\n1)
(A)--(B);
\foreach \p/\pos in {A/-90, B/-90,C/45,D/135,M/-135, N/-45}
\fill(\p)circle(1.pt) node[shift={(\pos:8pt)}]{$\p$};
\end{tikzpicture}
\end{document}
答案1
由 设置的(非恒等)变换矩阵scale=2
被应用两次,一次由 施加\pgfintersectionofpaths
,一次由 施加\pgfcoordinate
。
\pgf@giao
在下面的例子中,通过将逆变换矩阵(一次)应用于、\pgfintersectionofpaths
和之间来解决问题\pgfcoordinate
。
此外,最后两行\tikzdeclarecoordinatesystem{giaodiemthangtron}{...}
被注释掉,因为
\pgf@process{...}
已经在全球范围内设置\pgf@x
,\pgf@y
并且- 有点奇怪的是,一个坐标节点(此处
giaodiem
)会根据每个坐标(此处)自动(重新)定义一次又一次(giaodiemthangtron cs: <key-vals>)
。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc, intersections}
\makeatletter
\tikzset{/tikz/giaodiemthangtron cs/.cd,
thang line initial coordinate/.store in=\tikz@giaodiem@onA,
thang line final coordinate/.store in=\tikz@giaodiem@onB,
tron line initial coordinate/.store in=\tikz@giaodiem@andC,
tron line final coordinate/.store in=\tikz@giaodiem@andD,
thang/.style args={#1--#2}{
thang line initial coordinate=#1,
thang line final coordinate=#2,
},
tron/.style args={#1--#2}{
tron line initial coordinate=#1,
tron line final coordinate=#2,
},
point/.store in=\point,
}
\tikzdeclarecoordinatesystem{giaodiemthangtron}{
\tikzset{/tikz/giaodiemthangtron cs/.cd,#1}
% extract A and B
\pgfextract@process\pgf@giaodiem@onA
{\tikz@scan@one@point\pgfutil@firstofone(\tikz@giaodiem@onA)\relax}
\pgfextract@process\pgf@giaodiem@onB
{\tikz@scan@one@point\pgfutil@firstofone(\tikz@giaodiem@onB)\relax}
% extract C and D
\pgfextract@process\pgf@giaodiem@andC
{\tikz@scan@one@point\pgfutil@firstofone(\tikz@giaodiem@andC)\relax}
\pgfextract@process\pgf@giaodiem@andD
{\tikz@scan@one@point\pgfutil@firstofone(\tikz@giaodiem@andD)\relax}
% get radius rCD
\pgfpointdiff{\pgf@giaodiem@andC}{\pgf@giaodiem@andD}
\pgfmathveclen@{\pgfmath@tonumber\pgf@x}{\pgfmath@tonumber\pgf@y}
\edef\pgf@bankinhCD{\pgfmathresult pt}
% calculate intersections
\pgfintersectionofpaths
{%AB
\pgfpathmoveto{\pgf@giaodiem@onA}
\pgfpathlineto{\pgf@giaodiem@onB}
}
{%circle
\pgfpathcircle{\pgf@giaodiem@andC}{\pgf@bankinhCD}
}
\pgfextract@process\pgf@giao
{\pgfpointintersectionsolution{\point}}
% cancel the applied transformation
{%
\pgftransforminvert
\pgf@process{\pgfpointtransformed{\pgf@giao}}
}
% get intersections
% \pgfcoordinate{giaodiem}{}
% \tikz@scan@one@point\pgfutil@firstofone(giaodiem)\relax
}
\makeatother
\begin{document}
\begin{tikzpicture}[font=\small, scale=1]
\draw[help lines] (0,0) grid (5,3);
\path
(0,0) coordinate (A)
(5,1) coordinate (B)
(2,1) coordinate (C)
(1,2) coordinate (D)
(giaodiemthangtron cs: thang=A--B, tron=C--D, point=1) coordinate (M)
(giaodiemthangtron cs: thang=A--B, tron=C--D, point=2) coordinate (N);
\draw[blue]
let \p1 =($(C)-(D)$),
\n1 = {veclen(\x1,\y1)}
in
(C) circle (\n1)
(A)--(B);
\foreach \p/\pos in {A/-90, B/-90,C/45,D/135,M/-135, N/-45}
\fill (\p) circle (1.pt) node[shift={(\pos:8pt)}] {$\p$};
\end{tikzpicture}
\begin{tikzpicture}[font=\small, scale=2]
\draw[help lines] (0,0) grid (5,3);
\path
(0,0) coordinate (A)
(5,1) coordinate (B)
(2,1) coordinate (C)
(1,2) coordinate (D)
(giaodiemthangtron cs: thang=A--B, tron=C--D, point=1) coordinate (M)
(giaodiemthangtron cs: thang=A--B, tron=C--D, point=2) coordinate (N);
\draw[blue]
let \p1 =($(C)-(D)$),
\n1 = {veclen(\x1,\y1)}
in
(C) circle (\n1)
(A)--(B);
\foreach \p/\pos in {A/-90, B/-90,C/45,D/135, M/-135, N/-45}
\fill (\p) circle (1.pt) node[shift={(\pos:8pt)}] {$\p$};
\end{tikzpicture}
\begin{tikzpicture}[font=\small, xslant=.5]
\draw[help lines] (0,0) grid (5,3);
\path
(0,0) coordinate (A)
(5,1) coordinate (B)
(2,1) coordinate (C)
(1,2) coordinate (D)
(giaodiemthangtron cs: thang=A--B, tron=C--D, point=1) coordinate (M)
(giaodiemthangtron cs: thang=A--B, tron=C--D, point=2) coordinate (N);
\draw[blue]
let \p1 =($(C)-(D)$),
\n1 = {veclen(\x1,\y1)}
in
(C) circle (\n1)
(A)--(B);
\foreach \p/\pos in {A/-90, B/-90,C/45,D/135, M/-135, N/-45}
\fill (\p) circle (1.pt) node[shift={(\pos:8pt)}] {$\p$};
\end{tikzpicture}
\end{document}