TikZ を使用した三角形と座標系の描画

TikZ を使用した三角形と座標系の描画

私はTiを使用していますZ を初めて使用しましたが、何を表示させたいのか正確に把握できずに困っています。次の図を描こうとしています。

望んだ

これがコードです(あまり良くないことはわかっていますが、Tiを使用するのは初めてです)。Z):

\documentclass[paper=a4, fontsize=11pt]{scrartcl} % A4 paper and 11pt font size

\usepackage[T1]{fontenc}
\usepackage[english]{babel} % English language/hyphenation
\usepackage{amsmath,amsfonts,amsthm} % Math packages
\usepackage{graphicx}
\usepackage{mdframed}
\usepackage[ampersand]{easylist}
\usepackage{enumitem}
\usepackage{tikz}

\begin{document}
\begin{center}\begin{tikzpicture}[auto]
\draw[thick, ->] (-6,0) -- (10,0) node[anchor = north west] {x};
\draw[thick, ->] (0,-3) -- (0,11) node[anchor = south east] {y};
\node (P) at (-4,-2) {$P(-4;-2)$};
\node (Q) at (8,3) {$Q(8;3)$};
\node (R) at (4,10) {$R(4;10)$};
\node (N) at (2,7) {N};
\draw (P) to (Q);
\draw (R) to (Q);
\draw (P) to (R);
\draw (N) to (Q);
\end{tikzpicture}\end{center}
\end{document}

そして、現在は次のような結果が出ています:

出力

どうやって

  • ポイント名を取得するない線を切り抜け、
  • QN を結ぶ線を垂直線として描画しますか?

答え1

ここでは、多くの可能性のうちの 1 つを紹介します (90 度の角度マークの別の代替手段 - 他の角度については、anglesv3.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}

出力

Tiを開発している間Z-fu、私たちのアラン・マテスからのパッケージに注目してください。tkz-euclide。このタイプの図面を非常に簡単に、かつ構造的に作成できます。唯一の欠点は、マニュアルがフランス語であることです (文字通り)。しかし、それでもかなりわかりやすいです。

答え2

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}

ここに画像の説明を入力してください

答え3

比較のために、メタポスト

ここに画像の説明を入力してください

OP図の一番上の警告とは異なり、この図はスケール通りに描かれています...

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.

ここで幾何学について少し考えてみると、 はMy 軸上にあるので、 x 方向ではPと の中間にあるため、 の中点でなければならないことがわかります。したがって、 の座標は です。したがって、 から までの距離は ですが、これはから までの距離と同じで です。したがって、と は合同な三角形であり、したがって はの座標の中点です。Metapost 方程式システムを使用してこれを確認できます。次を追加します。RP--R(0,4)MQsqrt(8^2+1^2)=sqrt(65)RQsqrt(4^2+7^2)=sqrt(65)QNRQNMNR--M(2,7)

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

暗黙の定義がすでに与えられている場合、MP はエラーを発生しません。

答え4

不当に知られていないmfpicパッケージ。これは、METAFONT または MetaPost (この場合は後者) への非常に便利なインターフェイスを提供する、幅広い (La)TeX マクロのセットです。

ほとんどの人がこのパッケージに精通していないため、次のコードにはかなりの数のコメントを入れました。そのため、コードが比較的長くなっています。

MetaPost について少し知っている人であれば、mfpic生の MetaPost 命令を埋め込むこともできます。これは、より便利な場合があります。ここで私が行ったように、ポイント M と N を特定し (これは MetaPost によってトレードマークの暗黙的な方法で実行されます)、N に直角マークを描画します (MetaPost トランスフォーマーのおかげです)。

\documentclass{scrartcl}
% MetaPost instead of Metafont as drawing program and labels manager.
% Bounding box based on actual picture dimensions, not on the axes dimensions.
\usepackage[metapost, mplabels, truebbox]{mfpic}
% LaTeX preamble given to MetaPost for its labels management
% (corresponds to the verbatimtex ... etex flags of MetaPost)
\mfpverbtex{%&latex
    \documentclass{scrartcl}
    \begin{document}}
\setlength{\mfpicunit}{.5cm}
\opengraphsfile{\jobname}
\begin{document}
\begin{mfpic}[1]{-5}{9.5}{-3}{11}
    % Points definitions. For MetaPost they are local pairs.
    \setmfpair{P}{(-4, -2)}
    \setmfpair{Q}{(8, 3)}
    \setmfpair{R}{(4, 10)}
    % Point M computed by MetaPost as intersection of y-axis and straight line (PQ)
    \setmfpair{M}{(P -- R) intersectionpoint (origin -- (0, \ymax))}
    % Point N computed by MetaPost as intersection of line (PQ)
    % and the straight line perpendicular to (PQ) going through Q
    \mfsrc{save N; pair N; N = whatever[P, R] = whatever[Q, Q + (R-P) rotated 90];}
    % Mark angle beta with the convenient \arc macro of mfpic
    \store{mark_angle}\arc[a]{P, 0.8, angle(Q-P), angle(R-P)}
    % Mark right angle on N with help of MetaPost transformers
    \setmfvariable{path}{mark_right_angle}
        {((1, 0) -- (1, 1) -- (0, 1)) zscaled 0.3unitvector(Q-N) shifted N}
    % Actual drawings
    \polygon{P, Q, R}
    \lines{Q, N}
    \doaxes{xy}
    \mfobj{mark_angle}
    \mfobj{mark_right_angle}
    % Labels
    \tlpointsep{2bp} % Offset
    \tlabels{[tc]{(\xmax, 0)}{$x$} [cr]{(0, \ymax)}{$y$}
        [cr]{P}{$P(-4, -2)$} [cl]{Q}{$Q(8, 3)$} [bc]{R}{$R(4, 10)$}
        [br]{M}{$M$} [cr]{N}{$N$} [bl]{point 0.4 of mark_angle}{$\beta$}}
\end{mfpic}
\closegraphsfile
\end{document}

最初に (pdf)LaTeX でファイル.texをタイプセットし、次に結果の.mpファイルを MetaPost でタイプセットし、最後に LaTeX ファイルを再度 (pdf)LaTeX でタイプセットして、下の図を作成します。

ここに画像の説明を入力してください

関連情報