使用 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}

在此輸入影像描述

相關內容