使用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
它只是距離修飾符的包裝(請參閱 pgf 手冊的第 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}