0

I am trying to draw a triangle with arrows instead of line. This is what I have tried...

\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}

The problems:

  • Line needs to be arrows

  • from C to B & A to B & C to A

  • "A" label shouldn't be there in the line

  • General code and design formatting
  • Need to add an angle where C is
  • Remove all A, B, C labels

Something like this... Image

(Angle symbol is phi)

5 Answers5

2

Most of your question is answered by Marijn's link: use edges. In addition, you may want to use quotes and angles to address the other points. (I hope I have marked the right angle, your labels and coordinate names did not coincide.)

\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}

enter image description here

BTW, I think that the true angle is 33.69 degrees, at least the following computation seems to suggest it.

\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}

enter image description here

2

Just for fun, a short code with pstricks (if I've well understood what you want):

\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}

enter image description here

Bernard
  • 271,350
2

An another solution with 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}

enter image description here

Edit: defined and used new SI units for apparent and reactive power

Zarko
  • 296,517
2

With Lua and luacode. The lua language is used to make the necessary calculations in order to draw in scale.

\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}

enter image description here

2

With `tkz-euclide'. new version here 2.55. On CTAN in a few days

\documentclass[border=.25cm]{standalone}
\usepackage{tkz-euclide}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}[>=stealth,font=\footnotesize]
\tkzDefPoints{-1.5/-1/A,1.5/1/B,1.5/-1/C}
\tkzDrawSegments[->,shorten >=0.8pt](A,C C,B A,B)

\tkzMarkAngle[mark=none](C,A,B)
\tkzFindAngle(C,A,B) \tkzGetAngle{ang}
\tkzLabelAngle[right](C,A,B)%
            {$\phi=\pgfmathprintnumber{\ang}^\circ$}
\tkzLabelSegment(B,C){$Q = 37953.10 VAR$}
\tkzLabelSegment(C,A){$P = 67936 \si{\watt}$}
\tkzLabelSegment(A,B){$S = 77819.41 VA$}
\end{tikzpicture}
\end{document}

enter image description here

Alain Matthes
  • 95,075