和tikz-pgf
,我可以从一个点到一条线绘制垂直线。有没有一种可靠的方法来绘制垂直线从一个点?例如,在下面的代码中,假设我想从线上的一个特定点BC
向外画一条垂线。
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (2,4);
\coordinate (C) at (8,0);
\draw(A)--(B)--(C)--cycle;
\draw[red] (B) -- ($(A)!(B)!(C)$);
\node[label={below left:$A$}] at (A) {};
\node[label={above:$B$}] at (B) {};
\node[label={below right:$C$}] at (C) {};
\end{tikzpicture}
\end{document}
答案1
我刚刚写了这样的风格这个答案。我稍微改变了语法,所以你需要说
\draw[blue,vert={of {(B)--(C)} at (3,0)}];
在 处绘制一条垂直线,(3,0)
一直延伸到BC
。我添加了 ,vert outwards
它只是距离修饰符的包装器(请参阅 pgfmanual 的第 13.5.4 节“距离修饰符的语法”),可以用作
\draw[blue,vert outwards={from {($(B)!0.3!(C)$)} by 3cm on line to {(C)}}];
平均能量损失
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[vert/.style args={of #1 at #2}{insert path={%
#2 -- (intersection cs:first
line={#1}, second line={#2--($#2+(0,10)$)}) }},
vert outwards/.style args={from #1 by #2 on line to #3}{insert path={
#1 -- ($#1!#2!90:#3$)
}}]
\coordinate (A) at (0,0);
\coordinate (B) at (2,4);
\coordinate (C) at (8,0);
\draw(A)--(B)--(C)--cycle;
\draw[red] (B) -- ($(A)!(B)!(C)$);
\node[label={below left:$A$}] at (A) {};
\node[label={above:$B$}] at (B) {};
\node[label={below right:$C$}] at (C) {};
\draw[blue,vert={of {(B)--(C)} at (3,0)}];
\draw[blue,vert outwards={from {($(B)!0.3!(C)$)} by 3cm on line to {(C)}}];
\end{tikzpicture}
\end{document}
答案2
如果你愿意定义线上的特定点(B)--(C)
及其相对位置,那么你可以写你的姆韦如下简单的解决方案:
\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
\coordinate[label=below left:$A$] (A) at (0,0);
\coordinate[label=above:$B$] (B) at (2,4);
\coordinate[label=below right:$C$] (C) at (8,0);
\draw(A)--(B)-- coordinate[pos=0.3] (aux) % <--- coordinate of the point
(C)--cycle;
\draw[red] (aux) -- (aux |- A);
\end{tikzpicture}
\end{document}
答案3
抱歉,不是 tikz。我理解@hpekris 的想法。
\documentclass[pstricks,border=10pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\foreach \i in {.3,.5,.7}{
\begin{pspicture}[PointSymbol=none,linejoin=1](0,-1)(8,4)
\pnodes(0,0){A}(2,4){B}(8,0){C}(4,0){I}
\psline(A)(B)(C)(A)
\pstHomO[HomCoef=\i,PosAngle=75]{B}{C}[M]
\pstProjection[PosAngle=-90]{A}{C}{B}[H]
\pstProjection[PosAngle=-90]{A}{C}{M}[M']
\pcline(M)(M')
\pcline(B)(H)
\end{pspicture}}
\end{document}
答案4
另一个 PSTricks 解决方案仅用于比较目的。
我提供了一些可能的技巧,但你可以删除你不想要的部分。
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\foreach \i in {1,2,3}{%
\begin{pspicture}(8,5)
\pstTriangle(1,1){A}(7,1){B}(3,4){C}
\psline(C)(C|A)
\pnode([nodesep=\i]{B}C){P}
\psline(P)(P|A)
\pnode([nodesep=\i,offset=\i]{B}C){Q}
\psline[linecolor=red](P)(Q)
\end{pspicture}}
\end{document}