我正在尝试用箭头而不是线绘制三角形。这是我尝试过的……
\documentclass{article}
\usepackage{tikz}
\usepackage{siunitx}
\usepackage{float}
\title{}
\author{}
\date{}
\begin{document}
\begin{tikzpicture}[scale=1.25][H]
\coordinate [label=left:$C$] (A) at (-1.5cm,-1cm);
\coordinate [label=right:$A$] (C) at (1.5cm,-1cm);
\coordinate [label=above:$B$] (B) at (1.5cm,1cm);
\draw (A) -- node[left] {$S = 77819.41 VA$}
(B) -- node[right] {$Q = 37953.10 VAR$}
(C) -- node[below] {$P = 67936 \si{\watt}$} (A);
\end{tikzpicture}
\end{document}
存在的问题:
线需要是箭头
从 C 到 B & 从 A 到 B & 从 C 到 A
该行中不应有“A”标签
- 通用代码和设计格式
- 需要在 C 处添加一个角度
- 删除所有 A、B、C 标签
(角度符号为phi)
答案1
您的大部分问题都可以用以下方式回答Marijn 的链接:使用edge
s。此外,您可能希望使用quotes
和angles
来处理其他点。(我希望我标记的角度正确,您的标签和坐标名称不一致。)
\documentclass{article}
\usepackage{tikz}
\usepackage{siunitx}
\usetikzlibrary{angles,quotes}
\title{}
\author{}
\date{}
\begin{document}
\begin{tikzpicture}[scale=1.25]
\path[-stealth,shorten >=0.8pt] (-1.5cm,-1cm) coordinate (A)
(1.5cm,1cm) coordinate (B)
(1.5cm,-1cm) coordinate (C)
(A) edge["$S = 77819.41 VA$"] (B)
(C) edge["$Q = 37953.10 VAR$"'] (B)
(A) edge["$P = 67936 \si{\watt}$"'] (C);
\pic["$\alpha$",draw,angle eccentricity=1.1,"$\phi=\SI{29.19}{\degree}$"
{anchor=west,yshift=0.5ex}] {angle=C--A--B};
\end{tikzpicture}
\end{document}
顺便说一句,我认为真实角度是 33.69 度,至少下面的计算似乎表明了这一点。
\documentclass{article}
\usepackage{tikz}
\usepackage{siunitx}
\usetikzlibrary{angles,quotes,calc}
\title{}
\author{}
\date{}
\begin{document}
\begin{tikzpicture}[scale=1.25]
\path[-stealth,shorten >=0.8pt] (-1.5cm,-1cm) coordinate (A)
(1.5cm,1cm) coordinate (B)
(1.5cm,-1cm) coordinate (C)
(A) edge["$S = 77819.41 VA$"] (B)
(C) edge["$Q = 37953.10 VAR$"'] (B)
(A) edge["$P = 67936 \si{\watt}$"'] (C);
\path let \p1=($(B)-(A)$) in
pic["$\alpha$",draw,angle eccentricity=1.1,"$\pgfmathparse{atan2(\y1,\x1)}
\phi=\pgfmathprintnumber{\pgfmathresult}^\circ$"
{anchor=west,yshift=0.5ex}] {angle=C--A--B};
\end{tikzpicture}
\end{document}
答案2
只是为了好玩,一个简短的代码pstricks
(如果我很清楚你想要什么):
\documentclass{article}
\usepackage{pst-eucl}
\usepackage{siunitx}
\begin{document}
\begin{pspicture}(-2,-1.5)(2,1.5)
\footnotesize
\pstGeonode[PointSymbol=none, PointName=none](1.5,-1){A}(1.5,1){B}(-1.5,-1){C}
\psset{arrows=->, arrowinset=0.12, labelsep=2pt}
\ncline{C}{A}\nbput[labelsep=3pt]{$P =\SI{ 67936}{\W}$}
\ncline{C}{B}\naput{$S= \num{77819.41}\, VA$}
\ncline{A}{B}\nbput{$Q = \num{37953.10}\, VAR$}
%\foreach \S/\T in {A/B, C/A, C/B}{\ncline[arrows=->, arrowinset=0.12]{->}{\S}{\T}}
\pstMarkAngle[MarkAngleRadius=0.75, linewidth=0.5pt]{A}{C}{B}{$\varphi$}
\end{pspicture}
\end{document}
答案3
使用Lua和luacode
。使用lua语言进行必要的计算,以便按比例绘制。
\documentclass{article}
%\usepackage[utf8x]{inputenc}
\usepackage{luacode}
\usepackage{amsmath,graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{siunitx}
\sisetup{round-mode=places,round-precision=2}
\DeclareSIUnit \voltampere { VA } %apparent power
\DeclareSIUnit \voltamperereac { VAr } %reactive power
\begin{document}
\luaexec{
tp=tex.print
local P = 67936
local Q = 37953.10
local p =P/10000
local q =Q/10000
local S = math.sqrt(P*P+Q*Q)
local teta = math.atan(q/p)*(180/math.pi)
tp("\\begin{figure}[h]")
tp("\\centering")
tp("\\begin{tikzpicture}[>=latex]")
tp("\\coordinate (A) at(0,0);")
tp("\\coordinate (B) at("..p..",0);")
tp("\\coordinate (C) at("..p..","..q..");")
tp("\\draw [->](A)--(B)node[midway,below]{$P=\\SI{"..P.."}{\\watt}$};")
tp("\\draw [->](B)--(C)node[midway,right]{$Q=\\SI{"..Q.."}{\\voltamperereac}$};")
tp("\\draw [->](A)--(C)node[midway,above,sloped]{$S=\\SI{"..S.."}{\\voltampere}$};")
tp("\\path[clip] (A) -- (C) -- (B);")
tp("\\fill[red, opacity=0.5, draw=black] (A) circle (7mm);")
tp("\\node at ([xshift=10mm,yshift=-2mm]"..teta..":1) {$\\varphi=\\SI{"..teta.."}{\\degree}$};")
tp("\\end{tikzpicture}")
tp("\\caption{Power triangle.}")
tp("\\end{figure}")
}
\end{document}
答案4
另一个解决方案是tikz
:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{angles, arrows.meta,
quotes}
\usepackage{siunitx}
\DeclareSIUnit\voltampere{VA} % apparent power
\DeclareSIUnit\var{VAR} % reactive power
\begin{document}
\begin{tikzpicture}[auto,
> = {Straight Barb[angle=45:3pt 3]},
arr/.style = {->, very thick},
Angle/.style = {draw, <->,
angle radius = 12mm, angle eccentricity=1, anchor=west}
]
\draw[arr] (0,0) coordinate (A)
to["$S=\SI{77819.41}{\voltampere}$", sloped] (29.19:6) coordinate (C);
\draw[arr] (A) to["$P=\SI{77819.41}{\watt}$" '] (C |- A) coordinate (B);
\draw[arr] (B) to["$Q=\SI{37953.10}{\var}$" '] (C);
\pic[Angle,"$\varphi=\SI{29.19}{\degree}$"] {angle=B--A--C};
\end{tikzpicture}
\end{document}
编辑:定义并使用新的 SI 单位来表示视在功率和无功功率