
答え1
図書館を利用することができますcalc
。
\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (3,1);
\fill (A) circle (0.1);
\fill (B) circle (0.1);
\draw (A) node[below] {A} -- (B) node[below] {B} -- ($ (B)!1!-90:(A) $) -- ($ (A)!1!90:(B) $) -- cycle;
\end{tikzpicture}
\end{document}
答え2
このtkz-euclide
パッケージには、事前に定義された 2 つの座標から正方形を作成する機能など、幾何学的構成を作成するための多くの機能があります。
\tkzDefSquare(A,B)
\tkzGetPoints{C}{D}
A
最初の行は、 とに基づいて正方形を定義しますB
。 2 行目は、最後の 2 つのコーナーの座標を取得し、名前付き座標C
とを作成しますD
。
\documentclass[border=1cm]{standalone}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (3,1);
\tkzDefSquare(A,B)
\tkzGetPoints{C}{D}
\tkzDrawPoints[size=8](A,B,C,D)
\tkzDrawPolygon(A,B,C,D)
\end{tikzpicture}
\end{document}
答え3
\documentclass[tikz, border=1cm]{standalone}
\usepackage{xparse}
\makeatletter
\NewDocumentCommand { \mysquare } { s O{} D(){a} D(){b} }
{
\tikz@scan@one@point\pgf@process(#3)
\pgf@xa = \pgf@x
\pgf@ya = \pgf@y
\tikz@scan@one@point\pgf@process(#4)
\pgfmathsetmacro{\square@l}{
sqrt( (\pgf@x - \pgf@xa)^2 + (\pgf@y - \pgf@ya)^2 )
}
\def\square@sign{}
\IfBooleanT { #1 } { \def\square@sign{-} }
\draw[#2] (#3) -- (#4)
-- ([turn]\square@sign 90:\square@l pt)
-- ([turn]\square@sign 90:\square@l pt)
-- cycle;
}
\makeatother
\begin{document}
\begin{tikzpicture}
\coordinate [label=below left:$A$] (a) at (0, 0);
\coordinate [label=right:$B$] (b) at (2, 3);
\coordinate [label=above:$C$] (c) at (2, 1);
\mysquare[thick](a)(b)
\mysquare*[thick, red](a)(c)
\end{tikzpicture}
\end{document}