越来越少
越来越少
这家伙很懒,什么也没写!

注册于 5年前

回答
36
文章
0
关注者
1

可能需要看一下 \tkzSetUpLine 的定义, 当命令结束并且换行时, 应当添加注释符号, 否则可能产生空格, 这应该是 TeX 的特性. 也需要查看主命令内部所调用的命令的定义代码是否出现这种情况, 当出现多层次调用时, 需要检查的代码就多了.

\documentclass[border=3pt]{standalone}
\usepackage{tkz-euclide}
\begin{document}
\makeatletter
\def\tkzSetUpLine{\pgfutil@ifnextchar[{\tkz@SetUpLine}{\tkz@SetUpLine[]}}
\def\tkz@SetUpLine[#1]{%
\pgfkeys{%
      tkzsuline/.cd,
      line width   = \tkz@euc@linewidth,
      color        = \tkz@euc@linecolor,
      style        = \tkz@euc@linestyle,
%      add          = {\tkz@euc@lineleft} and {\tkz@euc@lineright},
}%
\pgfqkeys{/tkzsuline}{#1}%
\tikzset{%
        line style/.append style ={%
        line width        = \tkz@line@width,
        color             = \tkz@line@color,
        style             = \tkz@line@style,
%        add               = {\tkz@line@left} and {\tkz@line@right},
        line cap          = round,
        #1}
        }%
}%

\begin{tikzpicture}
    \tkzDefPoints{0/0/A,1/1/B}
    \tkzDrawSegments[thick](A,B)
\end{tikzpicture}

\begin{tikzpicture}[thick]
    \tkzDefPoints{0/0/A,1/1/B}
    \tkzDrawSegments(A,B)
\end{tikzpicture}

\begin{tikzpicture}[line style/.append style={line width=1pt}]
    \tkzDefPoints{0/0/A,1/1/B}
    \tkzDrawSegments(A,B)
\end{tikzpicture}

\tkzSetUpLine[line width=1pt]%
\tkzSetUpLine[line width=1pt]%
\tkzSetUpLine[line width=1pt]%
\begin{tikzpicture}
    \tkzDefPoints{0/0/A,1/1/B}
    \tkzDrawSegments(A,B)
\end{tikzpicture}

\end{document}

a9009ba518ecb6424dcdf03abda9ef5a.png

tikzpicure 环境内部, 文本字符被设置为 \nullfont, 一般没有这个问题.

tkz-euclide 包的主要优势在于提供了一些计算工具, 不在于设置样式. 我倾向于只用这个包做计算.

可以用解析方式, 解方程得到答案, 然后利用计算的数据来绘图, 需要一定的计算量, 参考下图
b50ef0046d3701b8cd27a6501b17b44e.png

我懒得计算, 就用二分法来寻找点 E.

\begin{tikzpicture}
\def\thresholdvalue{0.0001}
\tkzDefPoints{0/0/O, -1/0/B, 1/0/D}
\coordinate (B') at(B);
\coordinate (D') at(D);
%用二分法寻找点 E
%当 |BD/CD - 3/4| <= \thresholdvalue 时, 停止
\def\calvalue{
  \tkzDefMidPoint(B',D')
  \tkzGetPoint{E}
  \tkzCalcLength(E,D)
  \tkzGetLength{lenED}
  \tkzInterCC[R](O,1)(D,\lenED)
  \tkzGetFirstPoint{A}
  \tkzDefPointBy[rotation=center E angle -45](D)
  \tkzGetPoint{E'}
  \tkzInterLL(A,D)(E,E')
  \tkzGetPoint{C}
  \tkzCalcLength(C,D)
  \tkzGetLength{lenCD}
  \edef\BDvsCD{\fpeval{2/\lenCD}}
  \edef\conditionA{\fpeval{(\BDvsCD - 3/4) > \thresholdvalue}}
  \ifnum\conditionA=1
    \coordinate (D') at(E);
    \expandafter\calvalue
  \else
    \edef\conditionB{\fpeval{(\BDvsCD - 3/4) < -\thresholdvalue}}
    \ifnum\conditionB=1
      \coordinate (B') at(E);
      \expandafter\expandafter\expandafter\calvalue
    \fi
  \fi
}

\calvalue

\node [below left] at(B){$B$};
\node [above right] at(D){$D$};
\node [above right] at(E){$E$};
\node [above right] at(A){$A$};
\node [right] at(C){$C$};
\draw (B) -- (A);
\draw (B) -- (D);
\draw (B) -- (C);
\draw (E) -- (C);
\draw (A) -- (C);

\path (E);
\pgfgetlastxy{\macrox}{\macroy}
\tkzpttocm(\macrox){Ex}
\tkzpttocm(\macroy){Ey}
\node [right,align=left] at(3,0) {$\frac{BD}{CD}=\BDvsCD$\\$E=(\Ex,\Ey)$};
\end{tikzpicture}

898bedd9ebeaa50259e3849aad2e2e4a.png

这是旋转位似变换.

%旋转位似变换
%#1, 变换的中心点
%#2, 被变换的点
%#3, 旋转角度
%#4, 位似比例
%#5, 结果点的名称
\def\RotHom#1#2#3#4#5{
  \tkzURotateAngle(#1,#3)(#2)
  \tkzGetPoint{rotated-point-temp}
  \tkzUHomo(#1,#4)(rotated-point-temp)
  \tkzGetPoint{#5}
}

题目中第一个图形画出的情况: 以 A 为中心, 旋转角度为 -45 度, 位似比例 sqrt(2), 把 x 轴变成直线 BE
1beae1c0e6a562518a89bf74babc046d.png

\begin{tikzpicture}
\tkzDefPoints{0/0/O,-4/0/B,4/0/C,0/4/A,-5/0/xmin,5/0/xmax,0/-5/ymin,0/5/ymax}
\begin{scope}[thick]
\draw [->] (xmin) -- (xmax) node[below]{$x$};
\draw [->] (ymin) -- (ymax) node[above]{$y$};
\end{scope}

\draw (A) node[right]{$A$} -- (B) node[below left]{$B$} -- (C) node[below]{$C$} -- cycle;

\def\RotAngle{-45}

\RotHom{A}{B}{\RotAngle}{sqrt(2)}{B'}
\RotHom{A}{C}{\RotAngle}{sqrt(2)}{C'}
\tkzDrawLine[add=-1cm and 1cm](B',C')

%取点 D, 把 D 变换为点 E
\foreach \i[count=\ci,evaluate={\j = \i*100}] in {0.3,0.6,0.8}{
  \coordinate [label=-90:$D$] (D\ci) at ($(B)!\i!(C)$);
  \coordinate [label=200:$E$] (E\ci) at ($(A)!sqrt(2)!\RotAngle:(D\ci)$);
  \draw [dashed,draw=red!\j!cyan] (A) -- (D\ci) -- (E\ci) -- cycle;
}

\end{tikzpicture}

对于第二个问题, 应该有多个情况, 参照下图:
30bb12f03be9efabeb27156c99ee9233.png
容易看出需要考虑以下点

N= (-3,-1), (-2,-2), (-1/2,-7/2), (3,-7)

所以
4b67acfb7fe5bdba4fa19d92bf5036f0.png

%#1, 变换中心点
%#2, 角度
%#3, 比例
\tikzset{rotate scale trf/.style args={c#1d#2r#3}{rotate around={#2:#1},scale around={#3:#1}}}

\begin{tikzpicture}
\tkzDefPoints{0/0/O,-4/0/B,4/0/C,0/4/A,0/3/F,-5/0/xmin,5/0/xmax,0/-5/ymin,0/5/ymax}
\begin{scope}[thick,>=Stealth]
\draw [->] (xmin) -- (xmax) node[below]{$x$};
\draw [->] (ymin) -- (ymax) node[above]{$y$};
\end{scope}
\node [right] at(F) {$F$};
\draw (A) node[right]{$A$} -- (B) node[below left]{$B$} -- (C) node[below]{$C$} -- cycle;

\draw [rotate scale trf=c{(A)}d{-45}r{sqrt(2)}]
  (-4,0) coordinate (B') -- (4,0) coordinate (C');
  
%\foreach [count=\ct, evaluate={\val = 100*\ct/8}]\CenterPt/\RotDegree/\ScaleNum in {F/45/sqrt(2),F/-45/sqrt(2),F/45/{1/sqrt(2)},F/-45/{1/sqrt(2)},F/90/1,F/-90/1}{
%  \path [rotate scale trf=c{(\CenterPt)}d{\RotDegree}r{\ScaleNum}]
%  [draw=red!\val!green]
%    (-4,0) coordinate (B') -- (4,0) coordinate (C');
%}

\foreach [count=\n,evaluate={\v=100*\n/4}] \NPt/\negRotDegree/\ScaleNum in {{-3,-1}/90/1,{-2,-2}/-45/sqrt(2),{-1/2,-7/2}/-45/{1/sqrt(2)},{3,-7}/-90/1}{
  \coordinate (N) at (\NPt);
  \fill (N) circle (2pt);
  \coordinate [rotate scale trf=c{(F)}d{\negRotDegree}r{\ScaleNum}] (M) at(\NPt);
  \fill (M) circle (2pt) node[above,circle,draw, inner sep=1pt]{\n};
  \draw [draw=red!\v!cyan](N) -- (M) -- (F) -- cycle;
}
\end{tikzpicture}

如果希望看到动态图, 建议使用其他软件, 例如 Geogebra.

12bcc3dda81f4424e1e2f0cd0d37f9e7.png

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,arrows.meta}
\usepackage{tkz-euclide}
\usepackage{xparse}
\usepackage{xstring}
\input{centroid_label.tex}%https://www.latexstudio.net/index/details/index/mid/4611.html

\begin{document}

\begin{tikzpicture}[scale=0.4]
%用面积条件计算得到 BD, AB 的长度
\edef\lenBD{\fpeval{sqrt(30)}}
\edef\lenAB{\fpeval{100/(sqrt(10)*3)}}
\let\lenBE\lenBD
\let\lenBC\lenAB
%已知 BG= BD
\let\lenBG\lenBD
\edef\lenAG{\fpeval{\lenAB-\lenBG}}
%余弦定理计算 AD
\edef\lenAD{\fpeval{sqrt(\lenBD*\lenBD+\lenAB*\lenAB-2*\lenBD*\lenAB*cosd(60))}}
%三角形 AGD 相似于三角形 AFB, 计算 AF
\edef\lenAF{\fpeval{\lenAG*\lenAB/\lenAD}}
%余弦定理计算 CE, 角 BCE
\edef\lenCE{\fpeval{sqrt(\lenBD*\lenBD+\lenAB*\lenAB-2*\lenBD*\lenAB*cosd(120))}}
\edef\angleBCE{\fpeval{acosd((\lenCE*\lenCE + \lenAB*\lenAB - \lenBD*\lenBD)/(2*\lenCE*\lenAB))}}

\coordinate (C) at(0,0);
\coordinate (E) at(\lenCE,0);
\coordinate (B) at(\angleBCE:\lenBC);

\coordinate (A) at($(B)!1!-90:(C)$);
\coordinate (D) at($(B)!1!90:(E)$);

\coordinate (G) at($(B)!\lenBG cm!(A)$);
\coordinate (F) at($(A)!\lenAF cm!(D)$);

\draw (A) -- (C) -- (E) -- (D) -- cycle;

\draw (B) edge (A) edge (C) edge (E) edge (D) edge (F);
\draw (G) edge (D) edge (F);

\LabelPts{A,B[-100],C,D,E,F,G[200]}

\coordinate (H) at($(G)!(A)!(F)$);
\draw (A) -- (H) node[anchor=240]{$H$};
\tkzCalcLength(A,H)
\tkzGetLength{lenAH}
%显示 AH 的长度
\node at (0,8) {$AH=\lenAH$};
\end{tikzpicture}

\end{document}

在 tikz 中, 一个路径只能加一个箭头, 所以给 plot 加上 -latex 来一次性加多个箭头很难.

plot 创建 plot stream, 用 plot handler 绘图, 这个思路的话, 可以这样试试:

\makeatletter

\def\mypointcode#1{
    \ifpgf@plot@started%
      \pgfsetarrowsend{Latex}
      \pgfpathmoveto{\lastpoint}%
      \pgfpathlineto{#1}
      \pgfusepath{stroke}
      \def\lastpoint{#1}
    \else%
      \def\lastpoint{#1}
      \def\firstpoint{#1}
      \pgf@plot@startedtrue% 
    \fi%
}
  
\def\myendcode{
      \pgfsetarrowsend{Latex}
      \pgfpathmoveto{\lastpoint}%
      \pgfpathlineto{\firstpoint}
      \pgfusepath{stroke}
}
\begin{tikzpicture}
\path[draw]
  foreach \x[
          evaluate = \x as \angle using {360/12*(\x+1/2)}
      ] in {0,...,11} {
          node[
              shape=circle, color=black, draw, fill,
              inner sep=+0pt, minimum size=+2pt,
              label = {[anchor=\angle+180]{\angle}:$\x$},
              ] (a\x) at (\angle:1.5) {}
  };

\pgfplothandlerrecord{\mystream}
\pgfplotfunction{\x}{0,...,11}{\tikz@scan@one@point\pgf@process(a\x.center)}
\let\pgfplotstreampoint\mypointcode
\let\pgfplotstreamend\myendcode
\tikzset{shorten <=1.5pt, shorten >=1.5pt}
\mystream
\end{tikzpicture}

87069d1406db373ab1438c506d5c5f79.png

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,graphs}

\begin{document}

\tikz[>=Latex]
  \graph[
    counterclockwise=12,
    radius=2cm,
    nodes={circle, fill, minimum size=4pt,inner sep=0pt},
    empty nodes,
    cycle,
    ->
  ]{ \foreach \i in {0,1,...,11}{""/""[label={90+\i*(360/12):$a_{\i}$}], } };

\end{document}

表面上看这个办法的代码简单, 只是表面上看.

6516d14e6c10661d5f59bb42e785ba2c.png

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{tkz-euclide}
\usepackage{xparse}
\usepackage{xstring}
\input{centroid_label.tex}%https://www.latexstudio.net/index/details/index/ids/4611

\begin{document}

\begin{tikzpicture}[font=\small]
    \def\lenBC{2}
    \def\lenCD{2.5}
    \pgfmathsetmacro{\lenBD}{\lenBC+\lenCD}

    \coordinate (B) at (0,0);
    \coordinate (C) at (\lenBC,0);
    \coordinate (A) at (60:\lenBC);
    \coordinate (D) at ($(C)!-\lenCD cm!(B)$);
    \coordinate (E) at ($(A)!-\lenBD cm!(B)$);
    \coordinate (G) at ($(A)!-\lenCD cm!(B)$);

    \tkzDrawPolygon[thick](A,B,C)
    \tkzDrawSegments[thick](C,D A,E E,C E,D G,D)

    \LabelPts{A[120],B,C,D,E,G[120,text=magenta]}
\end{tikzpicture}

\end{document}

上面利用 tikz 的 calc 库的句法来定义点 D, E.

tkz-euclide 包的命令 \tkzDefPointWith, \tkzCalcLength 的计算可能用 \fpeval 实现, 这与 tikz 的计算不同.

参考:
tkz-euclide 资料 1
tkz-euclide 资料 2
tikz 资料 3

8a95d7d175e16fe3a7c823a4dc17b37b.png

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{tkz-euclide}
\input{centroid_label.tex}

\begin{document}

\begin{tikzpicture}
\tkzDefPoints{0/0/A,5/0/B}
\tkzDefTriangle[two angles=40 and 50](A,B)
\tkzGetPoint{E}
\tkzDefMidPoint(A,B)
\tkzGetPoint{M}
\draw (A) -- (B) -- (E) -- cycle;
\draw (E) -- (M);
\tkzMarkRightAngle[size=0.2,color=red](A,E,B)
\LabelPts{A, B, E, M}

\tkzDefLine[parallel=through A, K=0.5](M,E)
\tkzGetPoint{A'}
\tkzDefLine[parallel=through B, K=0.5](M,E)
\tkzGetPoint{B'}

\coordinate (E') at ($(E)+(170:0.5)$);

\tkzInterLL(A,A')(E,E')
\tkzGetPoint{D}
\tkzInterLL(B,B')(E,E')
\tkzGetPoint{C}

\draw (A) -- (D) -- (C) -- (B);

\LabelPts{D,C}
\end{tikzpicture}

\end{document}

步骤:

  1. 直角三角形 AEB, 角 E=90 度
  2. 取 AB 的中点 M
  3. AD 平行于 EM, BC 平行于 EM

\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{3d}

\begin{document}
\begin{tikzpicture}[x={(1,0)}, y={(0,0.5)},z={(0,2)}]
\draw[color=red] (0,0,0) -- (1,0,0) node[right]{$x$};
\draw[color=blue] (0,0,0) -- (0,1,0) node[above]{$y$};
\draw[color=orange] (0,0,0) -- (0,0,1) node[left]{$z$};
\coordinate (A) at(-1,0);
\coordinate (B) at(1,0);
\draw[dashed] (1,0) arc (0:180:1 and 1);
\draw (-1,0) arc (180:360:1 and 1);
\begin{scope}[plane origin={(0,0,2)}, plane x={(1,0,3)}, plane y={(0,1,2)},canvas is plane]
\coordinate (A') at(-1,0);
\coordinate (B') at(1,0);
\draw (0,0) circle [x radius=1, y radius=1];
\end{scope}
\draw (A) -- (A');
\draw (B) -- (B');
\end{tikzpicture}
\end{document}

d8f72bd964ed964df5617ba4d0026801.png

\coordinate ["$P1$"] (P1) at ($(O1)!\length cm!\pgfmathresult:(O2)$);

\coordinate ["$P1$"] (P1) at ($(O1)!\length cm!\length cm:(O2)$);

是一样的.

\pgfmathparse 解析 \length cm, 得到 \pgfmathresult, 然后再解析 \pgfmathresult:(O2)这一部分.

多数 pgf 的数学函数都会把结果保存到 \pgfmathresult, 命令 \pgfmathparse 总会把结果保存到 \pgfmathresult.

如果需要某个 \pgfmathresult, 最好及时转存它的值.

具体原因见 tikz 的 calc 库.

参考这里提及的文章

或者使用 tikz 的 to 路径.

%\usetikzlibrary{topaths}
\begin{tikzpicture}
\draw [->] (-4,0) -- (4,0);
\draw [->] (0,-4) -- (0,4);
\def\rightpart{
    (0,0) to[out=-60,in=180,in looseness=0.5] (0.5,-0.5)
          to[out=0,in=180,out looseness=0.5,in looseness=0.5] (2,3)
          to[out=0,in=180,out looseness=0.5,in looseness=0.5] (2.5,2.5)
          to[out=0,in=-100,out looseness=0.5,in looseness=0.5] (3,3.5)
}
\draw \rightpart ;
\draw[rotate=180]\rightpart ;
\end{tikzpicture}

dc0a17a512da9e48ee2839868bb52fcd.png

电脑的计算几乎都是近似计算, 只要近似地还行, 不是切线也是切线.

\documentclass[tikz]{standalone}
\begin{document}

\begin{tikzpicture}[scale=1.5]

\tikzset{
  temp/.cd,
    s opt/.store in=\solidlineopt, s opt={draw=green},
    s path/.store in=\solidlinepath, s path=,
    s end opt/.store in=\solidlineendopt, s end opt={below},
    s end text/.store in=\solidlineendtext, s end text=,
    d opt/.store in=\dashedlineopt, d opt={draw=red,dashed},
    d path/.store in=\dashedlinepath, d path=,
    d end opt/.store in=\dashedlineendopt, d end opt={below},
    d end text/.store in=\dashedlineendtext, d end text=,
}
\def\linesdraw#1{
  \begingroup
    \tikzset{temp/.cd,#1}
    \edef\tempcmd{
      \noexpand\begin{scope}
        \noexpand\draw[\solidlineopt]\solidlinepath node[\solidlineendopt]{\solidlineendtext};
      \noexpand\end{scope}
      \noexpand\begin{scope}
        \noexpand\draw[yscale=-1,rotate=-90,\dashedlineopt]
          \dashedlinepath
          node[\dashedlineendopt]{\dashedlineendtext};
      \noexpand\end{scope}
    }
    \tempcmd
  \endgroup
}

\begin{scope}[rotate=-135]
\foreach \i/\j/\k in {
{(4,4)--(4,0)arc(0:-180:1.5)--(1,5)}/{$+a_{12}a_{23}a_{31}$}/{$-a_{12}a_{21}a_{33}$},
{(3,3)--(3,0)arc(0:-180:1.5)--(0,5)}/{$+a_{13}a_{21}a_{32}$}/{$-a_{11}a_{23}a_{32}$},
{(2,0)--(2,5)}/{$+a_{11}a_{22}a_{33}$}/{$-a_{13}a_{22}a_{31}$}
}{
\linesdraw{
%  s opt=,
  s path={\i},
%  s end opt={},
  s end text={\j},
%  d opt=,
  d path={\i},
%  d end opt={},
  d end text={\k},
}}
\end{scope}

\begin{scope}[yscale={-sqrt(2)},xscale={sqrt(2)},shift={(-2,0)}]
\foreach \i in {1,2,3}{
\foreach \j in {1,2,3}{
  \node [fill=white] at(\i,\j){$a_{\j\i}$};
}}
\end{scope}

\end{tikzpicture}

\end{document}

d6d10b231447de91db2afa74bae60696.png

试试下面的代码。

\documentclass{article}
\usepackage{geometry}
\geometry{papersize={16cm,9cm}, hmargin=2cm,vmargin=1.5cm}
\usepackage{tikz}

\begin{document}

XXXXX XXXXX XXXXX XXXXX 
XXXXX XXXXX XXXXX XXXXX 
XXXXX XXXXX XXXXX XXXXX 

\begin{tikzpicture}[remember picture]
  \node[draw=red](A)at(1,1){something};%
  \path (A.south west);%
  \pgfgetlastxy{\Ax}{\Ay}%
  \path [overlay] (current page.south west);%
  \pgfgetlastxy{\Px}{\Py}%
  \pgfmathparse{\Ax-\Px}%
  \edef\APx{\pgfmathresult pt}
  \pgfmathparse{\Ay-\Py}%
  \edef\APy{\pgfmathresult pt}
  \edef\APcoord{\APx,\APy}%
  \draw [overlay] (current page.south west) -- node[sloped,align=left]{\APx,\\ \APy} ++(\APcoord);%
\end{tikzpicture}

XXXXX XXXXX XXXXX XXXXX 
XXXXX XXXXX XXXXX XXXXX 
XXXXX XXXXX XXXXX XXXXX 

\end{document}

结果如图:
result.png

不能。一个路径只能有一个颜色。似乎pdf格式就是这样的,记不准确了。

发布
问题