TikZ 的平行四边形

TikZ 的平行四边形

下列情况该如何改善?

\documentclass[tikz,border=7mm]{standalone}
\begin{document}
  \begin{tikzpicture}[xslant=1,xscale=3,scale=2]
    \draw (0,0) rectangle
          (1,1) coordinate(C) node[above]{C} -- (0,0) coordinate(A) node[below]{A}
          (1,0) coordinate(D) node[below]{y} -- (0,1) coordinate(B) node[above]{x};
  \end{tikzpicture}
\end{document}

我想要放置在如下图所示的线条下方x+yx-y

在此处输入图片描述

答案1

实际上,tkz-euclide v2.42b (beta)这里

%!TEX TS-program = lualatex
\documentclass{standalone}
\usepackage{tkz-euclide}

\begin{document}

\begin{tikzpicture}[scale=1.5]
    %initialisation
    \tkzInit[xmin=0,xmax=4,ymin=0,ymax=2] 
    \tkzClip[space=.5] 
    %definitions
    \tkzDefPoint(0,0){A} 
    \tkzDefPoint(3,0){B} 
    \tkzDefPoint(4,2){C} 
    \tkzDefPointWith[colinear= at C](B,A) \tkzGetPoint{D}
    %drawing
    \tkzDrawPolygon(A,B,C,D)
    \tkzDrawSegments[blue,dashed](A,C B,D)
    %label
    \tkzLabelPoints(A,B)
    \tkzLabelPoints[above right](C,D)
    \tkzLabelSegment[above,pos=.7,sloped](A,C){$x+y$}
    \tkzLabelSegment[above,pos=.7,sloped](B,D){$x-y$}
\end{tikzpicture}

 \end{document}

在此处输入图片描述

答案2

看看以下内容是否是您想要的:

\documentclass[tikz, margin=7mm]{standalone}
\usetikzlibrary{quotes}

\begin{document}
  \begin{tikzpicture}[xslant=1,xscale=3,yscale=2,
                      every node/.append style={inner xsep=0pt}
                      ]
    \draw (0,0) rectangle   (1,1);
    \draw (0,1) node[above] {$u$}
                to ["$u+y$",pos=0.3,swap] (1,0) node[below]{$y$}
          (0,0) to ["$u-y$",pos=0.7] (1,1);
\end{document}

在此处输入图片描述

或者

\documentclass[tikz, margin=7mm]{standalone}
\usetikzlibrary{quotes}

\begin{document}
  \begin{tikzpicture}
    \node (n) [draw, minimum width=3cm, minimum height=2cm, xslant=1] {};
    \draw (n.south west) to ["$u+y$",pos=0.7,sloped] (n.north east)
          (n.north west) node[above] {$u$} 
                         to ["$u-y$",pos=0.3,sloped] (n.south east) node[below] {$y$};
  \end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

您可以定义一个pic绘制平行四边形的函数。平行四边形由两个相邻边的长度和它们之间的角度定义。这些分别存储在目录中的键xy和中。使用 ,如果您绘制多个坐标名称,则可以使坐标名称唯一。要绘制平行四边形,您只需说angleparallelogramname prefix

\draw (<x>,<y>) pic[name prefix=para1-]{parallelogram={x=<lenght 1>,y=<lenght 2>,angle=<angle>}};

这是一个例子(如果我们删除(<x>,<y>)它,它就是默认坐标(0,0))。

\documentclass[tikz,border=7mm]{standalone}
\begin{document}
  \begin{tikzpicture}[pics/parallelogram/.style={code={
   \tikzset{parallelogram/.cd,#1}
   \draw[pic actions] (0,0) coordinate (A) 
    -- ++ (0:\pgfkeysvalueof{/tikz/parallelogram/x}) coordinate (B) 
    -- ++ (\pgfkeysvalueof{/tikz/parallelogram/angle}:\pgfkeysvalueof{/tikz/parallelogram/y}) coordinate (C) 
    -- ++ (180:\pgfkeysvalueof{/tikz/parallelogram/x}) coordinate (D) 
    -- cycle;       
   }},parallelogram/.cd,x/.initial=1,y/.initial=1,angle/.initial=45]
    \draw pic[name prefix=para1-]{parallelogram={x=4,y=2.5,angle=45}};
    \draw (para1-A) -- (para1-C) node[pos=0.33,sloped,above]{$u+y$};
    \draw (para1-D) node[above left]{$u$} -- (para1-B) node[below right] {$y$}
    node[pos=0.33,sloped,above]{$u-y$};
  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容