我是 tikz 的新手,我正在尝试通过以下方式在三角形上制作垂直角标记
\path[clip](C)--($(B)!(A)!(C)$)--(A);
和
\node[draw=black, rectangle,inner sep=0pt, outer sep=0pt, minimum size=4mm] at ($(B)!(A)!(C)$){};
但我只得到了角度正方形的底部。
我想省去为正方形寻找正确旋转角度的麻烦。那么有没有更简单的方法来绘制旋转的直角标记?
下面是我的形状的代码。
\begin{tikzpicture}
\coordinate[label=-90:$A$] (A) at (0,0);
\coordinate[label=-90:$C$] (C) at (4,0);
\coordinate[label=45:$B$] (B) at (1.25,3);
\draw (A)--(B)--(C)--(A);
\draw ($(A)!(B)!(C)$)--(B);
\draw ($(B)!(A)!(C)$)--(A);
\draw ($(A)!(C)!(B)$)--(C);
\begin{scope}
\path[clip](B)--($(A)!(B)!(C)$)--(C);
\node [draw=black, rectangle,minimum size=4mm,inner sep=0pt,outer sep=0pt] at ($(A)!(B)!(C)$) {};
\end{scope}
\path[clip](C)--($(B)!(A)!(C)$)--(A);
\node[draw=black, rectangle,inner sep=0pt, outer sep=0pt, minimum size=4mm] at ($(B)!(A)!(C)$){};
\begin{scope}
\end{scope}
\begin{scope}
\end{scope}
\end{tikzpicture}
感谢您的帮助。
答案1
如果问题是“为什么我的代码不起作用”:
问题是你必须按照角度的方向旋转节点。
如果问题是“如何画直角”:
您可以定义to path
名为 example 的样式square
并像这样使用它
\draw[red] (A') to[square] (C);
在 (A') 处以方向 (C) 画直角。
以下是完整示例:
\documentclass[tikz,border=1cm]{standalone}
\usetikzlibrary{calc}
\tikzset{square/.default={2mm},
square/.style= { to path={($(\tikztostart)!#1!(\tikztotarget)$)
-- ($(\tikztostart)!#1!(\tikztotarget)!#1!-90:(\tikztotarget)$)
-- ($(\tikztostart)!#1!-90:(\tikztotarget)$)
(\tikztotarget)}}
}
\begin{document}
\begin{tikzpicture}
\coordinate[label=-90:$A$] (A) at (0,0);
\coordinate[label=-90:$C$] (C) at (4,0);
\coordinate[label=45:$B$] (B) at (1.25,3);
\draw (A)--(B)--(C)--(A);
\draw (B) -- ($(A)!(B)!(C)$) coordinate (B');
\draw (A) -- ($(B)!(A)!(C)$) coordinate (A');
\draw (C) -- ($(A)!(C)!(B)$) coordinate (C');
\draw[red] (A') to[square] (C);
\draw[green] (B') to[square] (A);
\draw[blue] (C') to[square] (B);
\end{tikzpicture}
\end{document}
笔记:关于如何画直角,还有其他问题。
答案2
这是一个rotate along
将原点移动到第一个指定点然后沿着从第一个点到第二个点的线旋转变换矩阵的关键。
\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{calc}
\makeatletter
\tikzset{rotate along/.code args={(#1)#2--#3(#4)}{%
\pgfmathanglebetweenpoints{\tikz@scan@one@point\pgf@process(#1)}%
{\tikz@scan@one@point\pgf@process(#4)}%
\let\tikz@tmp=\pgfmathresult
\tikzset{shift={(#1)}, rotate=\tikz@tmp}%
}}
\begin{document}
\begin{tikzpicture}
\coordinate[label=-90:$A$] (A) at (0,0);
\coordinate[label=-90:$C$] (C) at (4,0);
\coordinate[label=45:$B$] (B) at (1.25,3);
\draw (A)--(B)--(C)--(A);
\draw (B) -- ($(A)!(B)!(C)$) coordinate (B');
\draw (A) -- ($(B)!(A)!(C)$) coordinate (A');
\draw (C) -- ($(A)!(C)!(B)$) coordinate (C');
\draw [red, rotate along=(C') -- (A)] ( 0.25,0) |- (0,0.25);
\draw [green, rotate along=(A') -- (B)] (-0.25,0) |- (0,0.25);
\draw [blue, rotate along=(B') -- (C)] ( 0.25,0) |- (0,0.25);
\end{tikzpicture}
\end{document}