我正在尝试从直角三角形 (OAB) 中的 O 向斜边画垂线。从它的垂线脚(例如 X0)向矩形轴画两条垂线,垂线脚分别为 A0 和 B0。同样,从 O 向 A0B0 线画垂线,垂线脚在轴上为 A1 和 B1。我想重复这个过程 2-3 次。到目前为止,我已经到达了以下点。
\documentclass[varwidth]{standalone}
\usepackage{tkz-euclide}
\usepackage{tikz}
\usepackage{xcolor}
\usetikzlibrary{calc,spy}
\makeatletter
\usetikzlibrary{angles, intersections, positioning, quotes}
\usepackage{siunitx}
\begin{document}
\centering
\begin{tikzpicture}[x=2cm,y=2cm,
spy using outlines={circle, size=3cm, connect spies}]
\path (0,0) coordinate[label=left:\Large $O$] (O) (0,3) coordinate[label=left:\Large $B$] (B) (4,0) coordinate[label=right:\Large $A$] (A);
\draw [thick, black] (O) -- (B) -- (A) -- cycle;
\draw [black!90, thick] (O) -- ($(B)!(O)!(A)$);
\fill [red!70] ($(B)!(O)!(A)$) node[right]{\Large $X_0$};
\end{tikzpicture}
\end{document}
我卡在了 X0。如何在 latex 代码中获取垂直线的脚?
答案1
如果我误解了这个问题,请原谅我,但它读起来就像你想递归地绘制高度。所以这里有一个替代方案元帖子裹着luamplib
……
使用以下命令进行编译lualatex
:
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
vardef recursive_pedal(expr level, o, a, b) =
save p; pair p; p = whatever[a,b]; p - o = whatever * (a-b) rotated 90;
if level > 1:
recursive_pedal(level - 1, p, o, a);
recursive_pedal(level - 1, p, o, b);
fi
draw o -- p withcolor Blues[6][level];
enddef;
beginfig(1);
pair O, A, B;
O = origin;
A = 377 right;
B = 233 up;
recursive_pedal(6, O, A, B);
draw O -- A -- B -- cycle;
label.llft("$O$", O);
label.lrt("$A$", A);
label.top("$B$", B);
endfig;
\end{mplibcode}
\end{document}
答案2
像这样?
(我不确定我是否正确理解了你的问题)
\documentclass[varwidth]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\centering
\begin{tikzpicture}[x=2cm,y=2cm,
% spy using outlines={circle, size=3cm, connect spies}
every label/.append style = {font=\large}
]
\draw[thick] (0,0) coordinate[label= left:$O$] (O) -- (0,3)
coordinate[label= left:$B$] (B) -- (4,0)
coordinate[label=right:$A$] (A) -- cycle;
\draw [thick] (O) -- ($(B)!(O)!(A)$) coordinate[red, label=above right:$X_0$] (x0);
\draw[dashed] (x0 -| O) coordinate[label= left:$B_0$] (b0) -|
(x0 |- O) coordinate[label=below:$A_0$] (a0);
\end{tikzpicture}
\end{document}
答案3
我相信Zarko 已经给你答案了你正在寻找Thruston 制作了一张美丽的照片。
让我在他的 Metapost 答案中添加一个 TikZ 解决方案。
通过\unexpanded
(我们只需要,因为我们想要的结果#4-1
)在\tikzPerpNameScheme
所有级别上存活下来,然后可以让\tikzPerpPrintScheme
坐标名称正确显示。
(在这种情况下,我们可以直接使用,[#2,#3]_{#1}^{#4}
但这使得自定义标签变得更容易。)
我无法找出遵循您的命名方案的正确规则。
代码 1(仅代码行)
\documentclass[tikz]{standalone}
\usetikzlibrary{calc, ext.misc}
\tikzset{
draw perpendicular from/.style args={#1 onto #2--#3 at level #4}{
/utils/exec=\pgfmathtruncatemacro\tikzPerpLevel{int(#4)},% sanitize input
draw perpendicular from'/.expanded={#1}{#2}{#3}{\tikzPerpLevel}},
draw perpendicular from'/.style n args={4}{
insert path={coordinate (#1>#2-#3<#4) at ($(#2)!(#1)!(#3)$)},
/utils/TeX/ifnum={#4>0}{% not yet at level 0? → recursion
draw perpendicular from'/.expanded=%
{#1>#2-#3<#4}{#1}{#3}{\pgfinteval{#4-1}},
draw perpendicular from'/.expanded=%
{#1>#2-#3<#4}{#1}{#2}{\pgfinteval{#4-1}}}{},
insert path={
(#1) edge[perpendicular line/.try=
{#4}{\tikzPerpLevel}] (#1>#2-#3<#4)}}}
\begin{document}
\begin{tikzpicture}[x=2cm, y=2cm]
\path[font=\Large] (0,0) coordinate[label=below left:$O$] (O)
(0,3) coordinate[label=left:$B$] (B)
(4,0) coordinate[label=right:$A$] (A);
\draw[
perpendicular line/.style 2 args={
color/.pgfmath wrap={blue!##1}{100*(#1+1)/(#2+1)}},
draw perpendicular from=O onto A--B at level 4];
\draw[thick] (O) -- (B) -- (A) -- cycle;
\end{tikzpicture}
\end{document}
代码 2(带标签)
\documentclass[tikz, convert]{standalone}
\usetikzlibrary{calc, ext.misc}
\newcommand*\tikzPerpNameScheme[4]{#1>#2-#3<#4} % no fancy math for TikZ names
\newcommand*\tikzPerpPrintScheme[4]{% (#1) onto [(#2)--(#3)] at level #4
[#2,#3]_{#1}^{#4}}
\tikzset{
draw perpendicular from/.style args={#1 onto #2--#3 at level #4}{
/utils/exec=\pgfmathtruncatemacro\tikzPerpLevel{int(#4)},% sanitize input
draw perpendicular from'/.expanded={#1}{#2}{#3}{\tikzPerpLevel}},
draw perpendicular from'/.style n args={4}{
insert path={
coordinate (\tikzPerpNameScheme{#1}{#2}{#3}{#4}) at ($(#2)!(#1)!(#3)$)},
/utils/TeX/ifnum={#4>0}{% not yet at level 0? → recursion
draw perpendicular from'/.expanded={%
\unexpanded{\tikzPerpNameScheme{#1}{#2}{#3}{#4}}}
{\unexpanded{#1}}{\unexpanded{#3}}{\pgfinteval{#4-1}},
draw perpendicular from'/.expanded={%
\unexpanded{\tikzPerpNameScheme{#1}{#2}{#3}{#4}}}
{\unexpanded{#1}}{\unexpanded{#2}}{\pgfinteval{#4-1}}}{},
insert path={
(#1) edge[perpendicular line/.try=
{#4}{\tikzPerpLevel}{\tikzPerpNameScheme{#1}{#2}{#3}{#4}}]
(\tikzPerpNameScheme{#1}{#2}{#3}{#4})}}}
\begin{document}
\begin{tikzpicture}[x=2cm, y=2cm]
\pgfmathsetseed{114666}
\path[font=\Large] (0+rnd,0+rnd) coordinate[label=below left:$O$] (O)
(0+rnd,3+rnd) coordinate[label=left:$B$] (B)
(4+rnd,0+rnd) coordinate[label=right:$A$] (A);
\draw[
perpendicular line/.style n args={3}{
color/.pgfmath wrap={blue!##1}{100*(#1+1)/(#2+1)}},
draw perpendicular from=O onto A--B at level 5]; % 9 crashes
\draw[thick] (O) -- (B) -- (A) -- cycle;
\end{tikzpicture}
\begin{tikzpicture}[x=2cm, y=2cm]
\path[font=\Large] (0,0) coordinate[label=below left:$O$] (O)
(0,3) coordinate[label=left:$B$] (B)
(4,0) coordinate[label=right:$A$] (A);
\draw[
perpendicular line/.style n args={3}{
dash pattern=on 1pt off #2pt-#1pt,
edge node={node[at end,
/utils/exec=\let\tikzPerpNameScheme\tikzPerpPrintScheme]{$#3$}}},
draw perpendicular from=O onto A--B at level 2];
\draw[thick] (O) -- (B) -- (A) -- cycle;
\node[below left] at (A|-B)
{$\tikzPerpPrintScheme{\mathit{point}}{p_1}{p_2}{\mathit{level}}$};
\end{tikzpicture}
\end{document}