Drawing of triangle and coordinate system using TikZ

I'll just show one out of many possibilities (and yet another alternative for 90-degrees angle mark - for other angles have a look at the angles library in the manual for v3.00-)

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[scale=5]% Scale it rather using too big dimensions in centimeters
\coordinate[label=below:{$P(-4,-2)$}](p) at (-4mm,-2mm);
\coordinate[label=right:{$Q(8,3)$}](q) at (8mm,3mm);
\coordinate[label=above:{$R(4,10)$}] (r) at (4mm,10mm);

\draw (p) -- (q) -- (r) -- cycle; %Look at the tip of the triangle with cycle or (p)
% Here is some black magic; start from q and draw to a point
% which is at the place along the line from p to r but at the 
% place where q is projected on that line.
\draw (q) -- ($(p)!(q)!(r)$) coordinate (s);
\draw ($(s)!0.5mm!(q)$) coordinate (t) -- ($(t)!0.5mm!90:(q)$) --($(s)!0.5mm!(r)$);
\end{tikzpicture}
\end{document}

output

While you are developing your TikZ-fu, keep an eye on the package from our own Alain Matthes, called tkz-euclide. It makes these kind of drawings really really easy and structured. The only downside is that the manual is French to me (literally). But it is pretty self-explanatory nevertheless.


With tkz-euclide:

\documentclass[11pt,a4paper]{article}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}
\tkzInit[xmin=-5,xmax=9,ymin=-3,ymax=11]
\tkzAxeXY
%\tkzGrid
\tkzDefPoint[label=below:{$P(-4,-2)$}](-4,-2){P}
\tkzDefPoint[label=right:{$Q(8,3)$}](8,3){Q}
\tkzDefPoint[label=above:{$R(4,10)$}](4,10){R}
\tkzDrawSegments(P,Q Q,R R,P)
\tkzDefPointBy[projection=onto P--R](Q)
\tkzGetPoint{N}
\tkzLabelPoints[above left](N)
\tkzDrawPoints[color=red](P,Q,R,N)
\tkzDrawSegment(Q,N)
\tkzMarkRightAngle[fill=lightgray](Q,N,R)
\tkzLabelAngle[pos=1.3](Q,P,R){$\beta$}
\tkzMarkAngle[arc=l,size=1cm](Q,P,R)
\end{tikzpicture}
\end{document}

enter image description here


And for comparison, with Metapost.

enter image description here

Note that unlike the warning at the top of the OP diagram, this one is drawn to scale...

prologues := 3;
outputtemplate := "%j%c.eps";

beginfig(1);
u := 5mm;

% axes
path xx, yy;
xx = (5 left -- 9 right) scaled u;
yy = (3 down -- 11 up) scaled u;
drawarrow xx withcolor .5 white; 
drawarrow yy withcolor .5 white;
label.rt (btex $x$ etex, point 1 of xx);
label.top(btex $y$ etex, point 1 of yy);

% define the points
pair M, N, P, Q, R;
P = (-4, -2) scaled u;
Q = ( 8,  3) scaled u;
R = ( 4, 10) scaled u;
M = yy intersectionpoint (P--R);
N = whatever[P,R]; (N-Q) dotprod (R-P) = 0;
%
% mark the right angle
draw unitsquare scaled 5 rotated angle (Q-N) shifted N withcolor .5 white;
% draw the lines
draw P--Q--R--cycle; draw Q--N;
% add the labels
label.ulft(btex $M$          etex, M);
label.ulft(btex $N$          etex, N);
label.top (btex $R\,(4;10)$  etex, R);
label.rt  (btex $Q\,(8;3)$   etex, Q);
label.lft (btex $P\,(-4;-2)$ etex, P);
% label the angle along the bisector
label(btex $\beta$ etex, P + 20 unitvector(Q+R-2P));
endfig;
end.

A little thought about the geometry here, shows us that since M is on the y-axis it is half way between P and R in the x-direction, so it must be the midpoint of P--R. It therefore has co-ordinates (0,4); and the distance from M to Q is therefore sqrt(8^2+1^2)=sqrt(65), but this is the same as the distance from R to Q, which is sqrt(4^2+7^2)=sqrt(65); hence QNR and QNM are congruent triangles, and therefore N is the midpoint of R--M with coordinates (2,7). You can use Metapost equation system to confirm this; if you add

M = (0,4) scaled u; N = (2,7) scaled u;

after the implicit definitions already given, then MP gives no error.

Tags:

Tikz Pgf