การใช้จุดอ้างอิงใน“ Stanli”
เมื่อใช้แพ็กเกจ "Stanli" เพื่อวาดพาราแกรมจำนวนหนึ่งเพื่อดึงกันและกันฉันจะตั้งค่าออฟเซ็ต สำหรับ MWE ที่แสดงจุดกำเนิดของแต่ละแผนภาพจะถูกกำหนดดังนี้:
- \ ชี้ {a-LD} {0} {22.5};
- \ ชี้ {a-FBD} {0} {22.5-6};
- \ ชี้ {a-SFD} {0} {22.5-14};
ดังที่แสดงพิกัด X เหมือนกันสำหรับจุดกำเนิดของแต่ละแผนภาพ อย่างไรก็ตามในการวางไว้ด้านล่างซึ่งกันและกันฉันตั้งค่าชดเชยตามพิกัด Y ค่าออฟเซ็ตคือ (-6) สำหรับแผนภาพแรกและ (-14) สำหรับแผนภาพที่สอง ฉันจะกำหนด 2 offsets เหล่านั้นภายในสภาพแวดล้อม tikz ได้อย่างไรเพื่อให้เป็น loca สำหรับรูปนี้เท่านั้นโดยที่ฉันสามารถได้รับอนุญาตให้ป้อนพิกัดจุดดังนี้:
Y1 = -6
Y2 = -14
- \ ชี้ {a-LD} {0} {22.5};
- \ ชี้ {a-FBD} {0} {22.5-Y1};
- \ ชี้ {a-SFD} {0} {22.5-Y2};
เนื่องจากฉันต้องป้อนค่าชดเชยเพียงครั้งเดียวและเปลี่ยนครั้งเดียวเนื่องจากฉันต้องป้อนหลายครั้งเมื่อเปลี่ยนฉันจึงต้องเปลี่ยนครั้งเดียวไม่ใช่หลายครั้ง
\documentclass{article}
\usepackage{amsmath}
\usepackage{stanli}
\begin{document}
\begin{center}
\begin{tikzpicture}
\draw[help lines,step=0.5](0,0) grid(15,24);
%%%%%%%%%%%%%%%%%%%%%%%%Loading%%%%%%%%%%%%%%%%
\point{a-LD}{0}{22.5};
\point{b-LD}{10}{22.5};
\point{su-LD}{2}{22.5+1.5};
\point{s-LD}{2}{22.5};
\point{sl-LD}{2}{22.5-0.5};
\point{TL-LD}{10}{22.5+2};
\point{CAP-LD}{10/2}{22.5-2.5};
% Elements
\beam{4}{a-LD}{b-LD};
%Supports
\support {1}{a-LD};
\support {2}{b-LD};
%Loads
\lineload{1}{a-LD}{b-LD}[0][2][0.035]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%First diagram%%%%%%%%%%%%%%%%%%
\point{a-FBD}{0}{22.5-6};
\point{b-FBD}{10}{22.5-6};
\point{TL-FBD}{2*10/3}{22.5-6};
\point{TLA-FBD}{2*10/3}{22.5-6+1.75};
\point{HR}{0-1.5}{22.5-6};
\point{VRA}{0}{22.5-6-1};
\point{VRB}{10}{22.5-6-1};
\point{CAP-FBD}{10/2}{22.5-6-3.5};
% Elements
\beam{4}{a-FBD}{b-FBD};
%%%%%%%%%%%%%%%%%Second diagram%%%%%%%%%%%%%%%%%%
\internalforces{a-FBD}{b-FBD}{-3}{6}[0][red]%[0]
\point{a-SFD}{0}{22.5-14};
\point{b-SFD}{10}{22.5-14};
\point{TL-SFD}{2*10/3}{22.5-14};
\point{TLA-SFD}{2*10/3}{22.5-14+1.75};
\point{VRA}{0}{22.5-14-1};
\point{VRB}{10}{22.5-14-1};
\point{CAP-SFD}{10/2}{22.5-14-3.5};
% Elements
\beam{4}{a-SFD}{b-SFD};
\internalforces{a-SFD}{b-SFD}{-3}{6}[3][red]%[0]
\end{tikzpicture}
\end{center}
\end{document}
คำตอบ
หากคุณต้องการY1และY2เป็นค่าคงที่คุณสามารถใช้\pgfmathdeclarefunctionเพื่อประกาศเป็นฟังก์ชันที่ไม่ประมวลผลอาร์กิวเมนต์ใด ๆ และเพียงแค่ส่งค่าคงที่
ในตัวอย่างด้านล่างฉันใช้\pgfkeysสำหรับกำหนดมาโคร\DeclareConstantและ\DeclareConstants.
\DeclareConstant{⟨name of constant⟩}{⟨value of constant⟩} ใช้สำหรับการประกาศค่าคงที่เดียว
สามารถประกาศค่าคงที่หลายรายการผ่าน\DeclareConstants:
\DeclareConstantsประมวลผลรายการ-pairs ที่คั่นด้วยเครื่องหมายจุลภาค:⟨name of constant⟩=⟨value of constant⟩
\DeclareConstants{
⟨name of constant 1⟩=⟨value of constant 1⟩,
⟨name of constant 2⟩=⟨value of constant 2⟩,
...
⟨name of constant k⟩=⟨value of constant k⟩,
}
ในกรณีที่ค่าของค่าคงที่มีเครื่องหมายจุลภาคเช่นเป็นตัวคั่นของอาร์กิวเมนต์ / ตัวถูกดำเนินการของฟังก์ชัน pgfmath อื่นค่านั้นสามารถ / จำเป็นต้องอยู่ในวงเล็บปีกกา:
⟨name of constant 2⟩={⟨value of constant 2⟩},
foobar={mod(-100,30)},
(ค่าคงที่foobarจะมีค่า -10 โทเค็นต่อไปนี้=จะถูกส่งต่อไป\pgfmathparseในระหว่างการกำหนดค่าและโทเค็นที่เป็นผลมาจากการ\pgfmathparseคำนวณในรูปแบบสิ่งที่ส่งเป็นค่าของค่าคงที่การคำนวณวิธีนี้จะไม่ทำซ้ำเมื่อใดก็ตามที่ ใช้ค่าคงที่ในคำถาม)
!!!!! โปรดทราบว่าด้วย\DeclareConstantและ\DeclareConstantsคุณสามารถแทนที่ฟังก์ชัน pgfmath ที่มีอยู่แล้วได้อย่างง่ายดาย !!!!!
ดังนั้นโปรดอย่าประกาศอย่างต่อเนื่องsinหรือcosหรือชอบ ;-)
ส่วน "97 การปรับแต่งกลไกทางคณิตศาสตร์" ของpgfmanual.pdfคู่มือสำหรับ TikZ และ pgf กล่าวเกี่ยวกับชื่อของฟังก์ชัน:
_ชื่อของฟังก์ชั่นที่สามารถประกอบด้วยพิมพ์ใหญ่พิมพ์เล็กหรือตัวอักษรตัวเลขหรือขีดเส้นใต้ สอดคล้องกับการเขียนโปรแกรมภาษาหลายชื่อฟังก์ชั่นไม่สามารถเริ่มต้นด้วยตัวเลขหรือมีช่องว่างใด ๆ
(จุลภาคปลอมที่อยู่ด้านหลังวลี "สามารถประกอบด้วย" อยู่ในคู่มือ - ฉันไม่ได้ลบออกเพื่ออ้างอย่างตรงไปตรงมา)
ดังนั้นคุณสามารถกำหนดค่าคงที่ / ฟังก์ชันY1ได้ แต่คุณไม่สามารถกำหนดค่าคงที่ / ฟังก์ชัน1Yได้
\documentclass{article}
\usepackage{amsmath}
\usepackage{stanli}
\newcommand\DeclareConstant[2]{%
\pgfkeys{/MyStuff/declare constant={#1}{#2}}%
}%
\newcommand\DeclareConstants[1]{\pgfkeys{/MyStuff/.cd,#1,}}%
\newcommand\exchangeargs[2]{#2#1}%
\makeatletter
\pgfkeys{%
/MyStuff/.unknown/.code=\pgfkeys{/MyStuff/declare constant={\pgfkeyscurrentname}{#1}},
/MyStuff/declare constant/.code 2 args=%
\begingroup
\pgfmathparse{#2}%
\ifcat$\detokenize{#1}$\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{%
\GenericError{\space\space\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces}%
{Constant declaration error: Name of constant not specified}%
{\space\space\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces You cannot declare a constant without\MessageBreak specifying its name.}%
{You need some sort of identifier for referencing the constant.}%
\ifcat$\detokenize\expandafter{\pgfmathresult}$\expandafter\@firstofone\else\expandafter\@gobble\fi
{%
\GenericError{\space\space\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces}%
{Constant declaration error: Value of constant not specified}%
{\space\space\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces You cannot declare a constant without\MessageBreak specifying its value.}%
{Which aspect of a constant could be constant if not its value?\MessageBreak So there must be a value!}%
}%
\endgroup
}{%
\ifcat$\detokenize\expandafter{\pgfmathresult}$\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{%
\GenericError{\space\space\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces}%
{Constant declaration error: Value of constant not specified}%
{\space\space\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces\@spaces You cannot declare a constant without\MessageBreak specifying its value.}%
{Which aspect of a constant could be constant if not its value?\MessageBreak So there must be a value!}%
\endgroup
}{%
\expandafter\endgroup
\expandafter\exchangeargs\expandafter{\expandafter{%
\expandafter\def
\expandafter\pgfmathresult
\expandafter{\pgfmathresult}%
}}{\pgfmathdeclarefunction*{#1}{0}}%
}%
},%
/MyStuff/declare constant/.value required,%
}%
\makeatother
\begin{document}
\begin{center}
\begin{tikzpicture}
% \DeclareConstant{Y1}{-3-3};
% \DeclareConstant{Y2}{-14};
\DeclareConstants{
Y1=-3-1-2, % yields Y1=-6
Y2={mod(-114,-100)}, % yields Y2=-14
% Y3=...,
% Y4=...,
% foobar=...,
% ...
};
\draw[help lines,step=0.5](0,0) grid(15,24);
%%%%%%%%%%%%%%%%%%%%%%%%Loading%%%%%%%%%%%%%%%%
\point{a-LD}{0}{22.5};
\point{b-LD}{10}{22.5};
\point{su-LD}{2}{22.5+1.5};
\point{s-LD}{2}{22.5};
\point{sl-LD}{2}{22.5-0.5};
\point{TL-LD}{10}{22.5+2};
\point{CAP-LD}{10/2}{22.5-2.5};
% Elements
\beam{4}{a-LD}{b-LD};
%Supports
\support {1}{a-LD};
\support {2}{b-LD};
%Loads
\lineload{1}{a-LD}{b-LD}[0][2][0.035]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%First diagram%%%%%%%%%%%%%%%%%%
\point{a-FBD}{0}{22.5+Y1};
\point{b-FBD}{10}{22.5+Y1};
\point{TL-FBD}{2*10/3}{22.5+Y1};
\point{TLA-FBD}{2*10/3}{22.5+Y1+1.75};
\point{HR}{0-1.5}{22.5+Y1};
\point{VRA}{0}{22.5+Y1-1};
\point{VRB}{10}{22.5+Y1-1};
\point{CAP-FBD}{10/2}{22.5+Y1-3.5};
% Elements
\beam{4}{a-FBD}{b-FBD};
%%%%%%%%%%%%%%%%%Second diagram%%%%%%%%%%%%%%%%%%
\internalforces{a-FBD}{b-FBD}{-3}{6}[0][red]%[0]
\point{a-SFD}{0}{22.5+Y2};
\point{b-SFD}{10}{22.5+Y2};
\point{TL-SFD}{2*10/3}{22.5+Y2};
\point{TLA-SFD}{2*10/3}{22.5+Y2+1.75};
\point{VRA}{0}{22.5+Y2-1};
\point{VRB}{10}{22.5+Y2-1};
\point{CAP-SFD}{10/2}{22.5+Y2-3.5};
% Elements
\beam{4}{a-SFD}{b-SFD};
\internalforces{a-SFD}{b-SFD}{-3}{6}[3][red]%[0]
\end{tikzpicture}
\end{center}
\end{document}