
を使って描きたい典型的な幾何学的構成がありますTikZ
。次のコードは線分 を与えますPQ
。線分 から単位下にあり、にTikZ
垂直で を通る線上に点を描くにはどうしたらよいでしょうか。これを行うには、プリアンブルに がなければならないと思います。(この点を R とラベル付けし、直角三角形 を描きます。) を使用して三角形が直角三角形であることを示す場合、プリアンブルにがなければならないのでしょうか。PQ
P
2\sqrt{2}
PQ
\usetikzlibrary{calc}
QPR
\tkzMarkRightAngle(Q,P,R);
\usepackage{tkz-euclide}
\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning,intersections,quotes}
\begin{document}
\begin{tikzpicture}
\draw[yellow, line width=0.1pt] (-1.75,-1.75) grid[xstep=0.5, ystep=0.5] (2.75,1.75);
\draw[draw=gray!30,latex-latex] (0,1.75) +(0,0.25cm) node[above right] {$y$} -- (0,-1.75) -- +(0,-0.25cm);
\draw[draw=gray!30,latex-latex] (-1.75,0) +(-0.25cm,0) -- (2.75,0) -- +(0.25cm,0) node[below right] {$x$};
\node[outer sep=0pt,circle, fill,inner sep=1.5pt,label={[fill=white]left:$P$}] (P) at (-1,-1) {};
\node[outer sep=0pt,circle, fill,inner sep=1.5pt, label={[fill=white]right:$Q$}] (Q) at (2,1) {};
\draw[green!20!white] (P) -- (Q);
\end{tikzpicture}
\end{document}
答え1
コード内の説明コメントを確認してください。
\documentclass{amsart}
\usepackage{tikz}
%% you need the following 2 lines to use \tkzMarkRightAngle
%\usepackage{tkz-euclide}
%\usetkzobj{all}
\usetikzlibrary{shapes,positioning,intersections,quotes,calc}
\begin{document}
\begin{tikzpicture}
\draw[yellow, line width=0.1pt] (-1.75,-5) grid[xstep=0.5, ystep=0.5] (2.75,1.75);
\draw[draw=gray!30,latex-latex] (0,1.75) +(0,0.25cm) node[above right] {$y$} -- (0,-1.75) -- +(0,-0.25cm);
\draw[draw=gray!30,latex-latex] (-1.75,0) +(-0.25cm,0) -- (2.75,0) -- +(0.25cm,0) node[below right] {$x$};
\node[outer sep=0pt,circle, fill,inner sep=1.5pt,label={[fill=white]left:$P$}] (P) at (-1,-1) {};
\node[outer sep=0pt,circle, fill,inner sep=1.5pt, label={[fill=white]right:$Q$}] (Q) at (2,1) {};
\draw[green!20!white] (P) -- (Q);
%% the perpendicular
\pgfmathparse{2*sqrt(5)}
\node[outer sep=0pt,circle, fill,inner sep=1.5pt,label={[fill=white]left:$R$}] (R) at ($ (P)!\pgfmathresult cm! -90:(Q) $) {};
\draw[green!20!white] (P) -- (R) -- (Q);
%% right angle with tkz-euclide
%\coordinate (p) at (P);
%\tkzMarkRightAngle[color=green!20!white](Q,p,R)
%\fill (p) circle (2.1pt); %% to make the dot above right angle again.
\coordinate (a) at ($ (P)!5mm! -45:(Q) $);
\draw[green!20!white] (a) -- ($(P)!(a)!(Q)$);
\draw[green!20!white] (a) -- ($(P)!(a)!(R)$);
\end{tikzpicture}
\end{document}
答え2
ご質問にお答えすると、tikz はほとんどすべてを pgfmathparse で実行しますが、これは C コードに似ています: 2*sqrt(5) は、デフォルトのスケールでは 4cm を超えます。($(P)!1!90:(Q)$) は、(P) から開始し、(Q) の方向から 90 度 (反時計回り) で (Q) までの距離の 1 倍に進むことを意味します。
\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning,intersections,quotes,calc}
\begin{document}
\begin{tikzpicture}
\draw[yellow, line width=0.1pt] (-1.75,-1.75) grid[xstep=0.5, ystep=0.5] (2.75,1.75);
\draw[draw=gray!30,latex-latex] (0,1.75) +(0,0.25cm) node[above right] {$y$} -- (0,-1.75) -- +(0,-0.25cm);
\draw[draw=gray!30,latex-latex] (-1.75,0) +(-0.25cm,0) -- (2.75,0) -- +(0.25cm,0) node[below right] {$x$};
\node[outer sep=0pt,circle, fill,inner sep=1.5pt,label={[fill=white]left:$P$}] (P) at (-1,-1) {};
\node[outer sep=0pt,circle, fill,inner sep=1.5pt, label={[fill=white]right:$Q$}] (Q) at (2,1) {};
\draw[green!20!white] (P) -- (Q);
\coordinate (R) at ($(P)!2cm*sqrt(5)!-90:(Q)$);
\node[outer sep=0pt,circle, fill,inner sep=1.5pt, label={[fill=white]right:$R$}] at(R) {};
\end{tikzpicture}
\end{document}
答え3
実際には、 の使用を強制されるわけではありません\usepackage{tkz-euclide}
。 は\tkzMarkRightAngle(Q,P,R)
pure よりも簡単な構造を提供するだけですtikz
が、@HarishKumar が行ったように、 のみを使用しても比較的簡単に実現できますtikz
。また、style
軸と点に を使用すると、コードがきれいになります。
\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}\small
\begin{tikzpicture}[outer sep=0pt,p/.style={circle, fill,inner sep=1.5pt},ax/.style={draw=gray!50,latex-latex}]
\draw[yellow,line width=0.1pt] (-2.75cm,-1.75cm) grid[xstep=0.5, ystep=0.5] (2.75cm,1.75cm);
\draw[ax](0,1.75cm) +(0,0.25cm) node[above] {$y$} -- (0,-1.75cm) -- +(0,-0.25cm);
\draw[ax](-2.75cm,0) +(-0.25cm,0) -- (2.75cm,0) -- +(0.25cm,0) node[right] {$x$};
\coordinate[p,label={[fill=white]below:$P$}] (P) at (-1cm,-1cm);
\coordinate[p,label={[fill=white]right:$Q$}] (Q) at (2cm,1cm);
\coordinate[p,label={[fill=white]left :$R$}] (R) at ($(P)!{2cm*sqrt(2)}!90:(Q)$);
\draw (P)--(R)--(Q)--(P)--cycle;
\coordinate (a) at ($(P)!4mm!45:(Q)$);
\draw ($(P)!(a)!(Q)$) -- (a) -- ($(P)!(a)!(R)$);
\end{tikzpicture}
\end{document}
答え4
興味のある人のために、それを行う方法(他の方法も含む)メタポスト。
PR が PQ に垂直で、P から単位だけ離れた PQ の下に位置する点 R は2\sqrt{2}
、次の命令で与えられます (u
ここでは単位長さcm
)。
R = P + 2u*sqrt2*unitvector(Q-P) rotated -90;
anglebetween
MetaPostのマクロメタファンP--Q
パラメータが 2 に設定されている場合、この形式では、交差する 2 つのセグメントとP--R
(3 番目の引数はラベルで、ここでは空の文字列)の間に直角マークを簡単に描画できanglemethod
ます。このパラメータのデフォルト値は 1 で、マークは円弧になります。マークの希望する長さは、別のパラメータの引数として指定する必要がありますanglelength
(デフォルトは 20 pt)。
anglemethod := 2; anglelength := 2mm;
draw anglebetween(P--Q, P--R, "");
見るMetafunマニュアル詳細な説明については、279 ページを参照してください。
\documentclass[border=2mm]{standalone}
\usepackage{luamplib}
\mplibsetformat{metafun}
\mplibtextextlabel{enable}
\begin{document}
\begin{mplibcode}
% Axes parameters
u := cm; % Unit length
xmin := -1.75u; xstep := .5u; xmax := 2.75u;
ymin := -5u; ystep := xstep; ymax := 1.75u;
% Triangle summits
pair P, Q, R; P = u*(-1, -1); Q = u*(2, 1);
R = P + 2u*sqrt2*unitvector(Q-P) rotated -90;
beginfig(1);
% Grid
drawoptions(withcolor yellow);
for i = ceiling(xmin/xstep) upto floor(xmax/xstep):
draw (i*xstep, ymin) -- (i*xstep, ymax);
endfor
for j = ceiling(ymin/ystep) upto floor(ymax/ystep):
draw (xmin, j*ystep) -- (xmax, j*ystep);
endfor
% Axes
drawoptions(withcolor .8white);
drawarrow (xmin, 0) -- (xmax, 0);
drawarrow (0, ymin) -- (0, ymax);
% Triangle
drawoptions(withcolor green);
path triangle; triangle = P--Q--R--cycle; draw triangle;
% Right-angle mark of length 2 mm (and no label)
anglemethod := 2; anglelength := 2mm;
draw anglebetween(P--Q, P--R, "");
% Labels
drawoptions();
label.bot("$x$", (xmax, 0)); label.lft("$y$", (0, ymax));
dotlabel.lft("$P$", P); dotlabel.rt("$Q$", Q); dotlabel.bot("$R$", R);
endfig;
\end{mplibcode}
\end{document}
LuaLaTeX でタイプセットします。出力: