使用 TikZ 进行计算

使用 TikZ 进行计算

我不明白为什么计算出来的值不正确。哪里出了问题?两个箭头的角度(起点和终点)应该相等。

\documentclass[10pt]{article}
\usepackage[a4paper,top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc,arrows.meta,bending,decorations.text,positioning}

\def\centerarct[#1](#2)(#3:#4:#5)% Syntax: [draw options] (center) (start angle:end angle:radius)
{ \path[#1] ($(#2)+({#5*cos(-#3+90)},{#5*sin(-#3+90)})$) arc [start angle={-#3+90}, end angle={-#4+90}, radius=#5)]; }

\def\vectorl[#1](#2)(#3:#4:#5:#6)% Syntax: [draw options] (center) (total:start:end:radius)
{ \centerarct[#1](#2)({#5/#3*360}:{(#4-1)/#3*360+360}:#6); }

\begin{document}
 \begin{tikzpicture}
  \vectorl[draw=yellow!75!white,line width=5mm](0,0)(2500:1:2500:4.75);
  \centerarct[{Triangle[width=9mm,length=5mm]}-,scale=1.175,draw=violet!75!white,line width=5mm, postaction={decorate,decoration={text along path,text align={center,left indent=2.5mm},text={Test},raise=-1.25mm}}](0,0)(345.6:374.4:4.75);
  \vectorl[{Triangle[width=9mm,length=5mm]}-,scale=1.4,draw=violet!75!white,line width=5mm, postaction={decorate,decoration={text along path,text align={center,left indent=2.5mm},text={Test},raise=-1.25mm}}](0,0 )(2500:101:2400:4.75);  
 \end{tikzpicture}
\end{document}

答案1

start angle={-#3+90}因为在 中有 eg \centerarct,所以需要在 的定义中添加一对额外的括号\vectorl,否则您将得到-x+360+90,而不是-(x+360)+90。即您需要{((#4-1)/#3*360+360)}

由于事物的定义方式,您需要交换黄色圆圈的起始/结束值的顺序。

\documentclass[10pt]{article}
\usepackage[a4paper,top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc,arrows.meta,bending,decorations.text,positioning}

\def\centerarct[#1](#2)(#3:#4:#5)% Syntax: [draw options] (center) (start angle:end angle:radius)
{ \path[#1] ($(#2)+({#5*cos(-#3+90)},{#5*sin(-#3+90)})$) arc [start angle={-#3+90}, end angle={-#4+90}, radius=#5)]; }

\def\vectorl[#1](#2)(#3:#4:#5:#6)% Syntax: [draw options] (center) (total:start:end:radius)
{ \centerarct[#1](#2)({#5/#3*360}:{((#4-1)/#3*360+360)}:#6); }

\begin{document}
\begin{tikzpicture}
  \vectorl[draw=yellow!75!white,line width=5mm](0,0)(2500:2500:1:4);

  \centerarct[{Triangle[width=9mm,length=5mm]}-,draw=violet!75!white,line width=5mm, postaction={decorate,decoration={text along path,text align={center,left indent=2.5mm},text={Test},raise=-1.25mm}}](0,0)(345.6:374.4:5);

  \vectorl[{Triangle[width=9mm,length=5mm]}-,draw=violet!75!white,line width=5mm, postaction={decorate,decoration={text along path,text align={center,left indent=2.5mm},text={Test},raise=-1.25mm}}](0,0)(2500:101:2400:6);  

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容