我正在尝试在 TikZ 中绘制以下内容:
这样 a=1/2、b=1/4 和 c=1/4。这些线必须与三角形边成直角。
最后,三角形的高为 1。
\documentclass[tikz]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0) ;
\coordinate (B) at ({sqrt(4/3}, 0) {};
\coordinate (C) at ({(sqrt(4/3)/2},1) {};
\node at (A) [below left] {1};
\node at (B) [below right]{2};
\node at (C) [above]{3};
\filldraw[opacity=.3, blue] (A) -- (B) -- (C) -- cycle;
\end{tikzpicture}
\end{document}
答案1
Tikz 提供:
重心坐标系(“13.2.2 重心系统”,第 136 页,pgfmanual,v3.1.4b)。
例子:
(barycentric cs:A=1/2,B=1/4,C=1/4)
通过 TikZ 库的投影修改器
calc
(“13.5.5 投影修改器的语法”,第 148 页,pgfmanual,v3.1.4b)。投影
P
示例AB
:($(A)!(P)!(B)$)
这里有一个使用这些特征(以及极坐标来定义顶点)的解决方案:
\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[node font=\scriptsize,inner sep=.5em]
\path (-150:2/3) coordinate (A) node[below left]{A};
\path ( -30:2/3) coordinate (B) node[below right]{B};
\path ( 90:2/3) coordinate (C) node[above]{C};
\path[fill=blue!30,draw=blue] (A) -- (B) -- (C) -- cycle;
\path (barycentric cs:A=1/2,B=1/4,C=1/4) coordinate (P) node[above]{P};
\fill (P) circle (1pt);
\draw[red] (P) -- ($(A)!(P)!(B)$);
\draw[red] (P) -- ($(B)!(P)!(C)$);
\draw[red] (P) -- ($(C)!(P)!(A)$);
\end{tikzpicture}
\end{document}
答案2
在我看来,这看起来像是一个 XY 问题。你真正想要的(或者你真正被要求做的)是生成一个所谓的三元图。幸运的是,有一个专门用于此的库:\usepgfplotslibrary{ternary}
。它附带pgfplots
基于 Ti 的钾Z. 我添加了括号是为了好玩,但也认为只使用图表会更好。请注意,此网站上已经有几篇帖子讨论了如何自定义这些图表,只需进行 Google 搜索即可site:tex.stackexchange.com ternary diagram
找到它们。
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc,decorations.pathreplacing}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.16}
\usepgfplotslibrary{ternary}
\begin{document}
\begin{tikzpicture}
\begin{ternaryaxis}
\addplot3 coordinates {(0.25,0.5,0.25)} ;
\path (0.25,0.5,0.25) coordinate (M)
(1,0,0) coordinate (C) (0,1,0) coordinate (A) (0,0,1) coordinate (B);
\end{ternaryaxis}
\draw (M) -- ($(B)!(M)!(C)$);
\draw (M) -- ($(A)!(M)!(B)$);
\draw (M) -- ($(C)!(M)!(A)$);
\begin{scope}[thick,decoration={brace,raise=1pt}]
\draw[decorate] (M) -- ($(B)!(M)!(C)$) node[midway,above=2pt,sloped]{$0.5$};
\draw[decorate] (M) -- ($(A)!(M)!(B)$) node[midway,right=2pt]{$0.25$};
\draw[decorate] ($(C)!(M)!(A)$) -- (M) node[midway,above=2pt,sloped]{$0.25$};
\end{scope}
\end{tikzpicture}
\end{document}
答案3
计算如下图所示:
对于高为 1 的三角形,b=c=0.25 且 a=0.5。
\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{intersections,calc}
\begin{document}
\begin{tikzpicture}[scale=2]
\coordinate (A) at (0,0);
\coordinate (B) at ({sqrt(4/3)}, 0) {};
\coordinate (C) at ({(sqrt(4/3)/2},1) {};
\filldraw[opacity=.3, blue] (A) -- (B) -- (C) -- cycle;
\node at (A) [below left] {1};
\node at (B) [below right]{2};
\node at (C) [above]{3};
%\draw (O)--++(0:1)coordinate(A)--++(120:1)coordinate(B)--cycle;
\draw ($(A)!0.375!(B)$)coordinate(X)--++(90:0.25)coordinate(P)--++(150:0.25)coordinate(Y);
\draw (P)--++(30:0.5)coordinate(Z);
\path[] let \p1 = ($ (X) - (P) $) in (X) -- (P) node[midway,below=-1mm,sloped]{\scalebox{0.25}{ \pgfmathparse{veclen(\x1,\y1)/28.4}\pgfmathresult cm}};
\path[] let \p1 = ($ (Y) - (P) $) in (Y) -- (P) node[above=-0.8mm,midway,sloped]{\scalebox{0.25}{ \pgfmathparse{veclen(\x1,\y1)/28.4}\pgfmathresult cm}};
\path[] let \p1 = ($ (Z) - (P) $) in (Z) -- (P) node[above=-0.8mm,midway,sloped]{\scalebox{0.25}{ \pgfmathparse{veclen(\x1,\y1)/28.4}\pgfmathresult cm}};
\end{tikzpicture}
\end{document}
答案4
(评论太长了)这么多人在这里提问,没有 MWE 和不正确的数据!如果 OP 至少没有提供正确的数据,我会删除。
\documentclass[tikz]{standalone}
\usetikzlibrary{calc,decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}[scale=4]
% suppose the altitude is 1
\pgfmathsetmacro{\a}{2*sqrt(3)/3}
\draw[teal]
(0,0) coordinate (1) node[below left]{1}--
(\a,0) coordinate (2) node[below right]{2}--
([turn]120:\a) coordinate (3) node[above]{3}--cycle;
\path
(.5*\a,0) coordinate (M)
+(90:.5) coordinate (I)
($(1)!(I)!(3)$) coordinate(N)
($(2)!(I)!(3)$) coordinate (P);
\draw[red]
(I)--(M) node[midway,right=1pt,cyan]{$a$}
(I)--(N) node[midway,below left,cyan]{$b$}
(I)--(P) node[midway,above left,cyan]{$c$};
\draw[decorate,decoration={brace,raise=1pt},cyan] (I)--(M);
\draw[decorate,decoration={brace,raise=1pt},cyan] (I)--(N);
\draw[decorate,decoration={brace,raise=1pt},cyan] (I)--(P);
\end{tikzpicture}
\end{document}