我在 Google 上搜索了很多,但没有找到任何相关内容。如何在 Tikz 中创建下图?
https://fr.wikipedia.org/wiki/Moment_d%27une_force#/media/Fichier:Momento_de_uma_for%C3%A7a..png
这是我目前所做的。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
% Define angle and force magnitude
\def\angle{70} % Angle in degrees
\def\Fnorm{3} % Magnitude of the force vector
% Define coordinates
\coordinate (O) at (0,0); % Origin
\coordinate (P) at (1,1); % tail of force
\coordinate (F) at ({1 + \Fnorm * cos(\angle)}, {1 + \Fnorm * sin(\angle)}); % Force head
% Calculate coordinates for point Q
\coordinate (Q) at ({1 + 1.2*cos(\angle)}, {1 + 1.2*sin(\angle)});
% Draw the force vector
\draw[-latex, thick, blue] (P) -- (F) node[midway, right] {$\vec{F}$};
% Draw position vectors
\draw[-latex, thick, red] (O) -- (P) node[midway, right] {$\vec{r}$};
\draw[-latex, thick, orange] (O) -- (Q) node[midway, left] {$\vec{r'}$};
\fill (Q) circle[radius=1pt] node[ left] {$Q$};
\fill (P) circle[radius=1pt] node[below right] {$P$};
\fill (O) circle[radius=1pt] node[ below] {$O$}; % origin
\end{tikzpicture}
\end{document}
如何才能轻松获得沿向量 OP 方向及其法线的投影、力矩臂和表示力矩向量的卷曲向量?
非常感谢您的帮助。
答案1
更新
为了获得PF
比 长 3 倍的长度OP
,我使用了let
操作。
\path let \p1=($(P)-(O)$),
\n1 = {veclen(\x1,\y1)},
in
(O)--(P)--([turn]\angle:\n1*\Fnorm])coordinate (F);
我改变了你定义坐标的方式,以简化计算。我做了很多改动,所以我没有时间解释所有改动。我会让你看一下代码,如果你有什么不明白的,就说出来,我会解释的。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,angles}
\begin{document}
\begin{tikzpicture}[every node/.style={font=\footnotesize}]
% Define angle and force magnitude
\def\angle{60} % Angle in degrees
\def\Fnorm{3} % Magnitude of the force vector
% Define coordinates
\coordinate[label=left:O] (O) at (0,0); % Origin
\coordinate (P) at (2,1); % tail of force
\path let \p1=($(P)-(O)$),
\n1 = {veclen(\x1,\y1)},
in
(O)--(P)--([turn]\angle:\n1*\Fnorm])coordinate (F);
\coordinate[label=left:Q] (Q) at ($(P)!.4!(F)$);
\fill (Q) circle[radius=1pt];
% Draw the force vector
\draw[-latex, thick, blue] (P) -- (F) node[midway, right] {$\vec{F}$};
% Draw position vectors
\draw[-latex, thick, red] (O) -- (P) node[midway, above,yshift=-3pt] {$\vec{r}$};
\draw[-latex, thick, orange] (O) -- (Q) node[midway, left] {$\vec{r'}$};
\fill (P) circle[radius=1pt] node[below right] {$P$};
\fill (O) circle[radius=1pt];% node[ below] {$O$}; % origin
\coordinate (H) at ($(O)!(F)!(P)$);
\draw(F)--(H)node[midway,right]{$F\sin\theta$};
\draw[dashed] (P)--($(P)!1.2!(H)$);
\coordinate(H') at ($(F)!(O)!(P)$);
\draw(O)--(H')node[midway,sloped,below]{$r\sin\theta$};
\draw[dashed] (P)--($(P)!1.5!(H')$);
\pic[draw,pic text=$\theta$,angle radius=4mm,angle eccentricity=1.35]{angle=O--P--H'};
\pic[draw,pic text=$\theta$,angle radius=4mm,angle eccentricity=1.35]{angle=H--P--F};
\node[inner sep=0pt] (Mo) at (barycentric cs:O=1,P=-.5 ,F=1){$M_o$};
\draw[->,very thick, blue] (Mo.south west)to[out=-90,in=-90,looseness=2](Mo.south east);
\end{tikzpicture}
\end{document}
答案2
我发布了更新后的代码作为答案。虽然与 wiki 图片相差甚远,但对其他人来说仍然有用。
\documentclass{standalone}
\usepackage{tikz}
\usepackage{amsmath} % for trigonometric functions
\begin{document}
\begin{tikzpicture}
% Draw axes
\draw[->] (-0.5,0) -- (3,0) node[right] {$x$};
\draw[->] (0,-0.5) -- (0,3) node[above] {$y$};
% Define point P
\coordinate (P) at (1,1);
% Define point O
\coordinate (O) at (0,0);
% Calculate coordinates of point Q
\pgfmathsetmacro{\phhi}{60} % angle in degrees
\pgfmathsetmacro{\magnitude}{3} % magnitude of vector PQ
\pgfmathsetmacro{\qx}{\magnitude * cos(\phhi)} % x-coordinate of Q
\pgfmathsetmacro{\qy}{\magnitude * sin(\phhi)} % y-coordinate of Q
% Define point Q
\coordinate (Q) at ({1 + \qx}, {1 + \qy});
% Calculate coordinates for parallel and perpendicular components of F
\pgfmathsetmacro{\thheta}{45} % angle in degrees
\pgfmathsetmacro{\parallelX}{\magnitude * cos(\phhi-\thheta)*cos(\thheta)} % x-coordinate of F_parallel
\pgfmathsetmacro{\parallelY}{\magnitude * cos(\phhi-\thheta)*sin(\thheta)} % y-coordinate of F_parallel
\coordinate (R) at ({1 + \parallelX}, {1 + \parallelY}); % Endpoint of F_parallel
\pgfmathsetmacro{\perpendicularX}{\magnitude * sin(\phhi-\thheta)*sin(\thheta)} % x-coordinate of F_perpendicular
\pgfmathsetmacro{\perpendicularY}{\magnitude * sin(\phhi-\thheta)*cos(\thheta)} % y-coordinate of F_perpendicular
\coordinate (S) at ({1 - \perpendicularX}, {1 + \perpendicularY}); % Endpoint of F_perpendicular
% Calculate coordinates of point T
\pgfmathsetmacro{\Tx}{sqrt(2) * cos(90-\phhi) * sin(\phhi-\thheta)} % x-coordinate of T
\pgfmathsetmacro{\Ty}{-sqrt(2) * sin(90-\phhi) * sin(\phhi-\thheta)} % y-coordinate of T
% Define point T
\coordinate (T) at (\Tx, \Ty);
% Draw vector PQ
\draw[-latex, thick] (P) -- (Q) node[midway, above] {$\vec{F}$};
% Draw vector OP
\draw[-latex, thick] (O) -- (P) node[midway, above] {$\vec{r}$};
% Draw vector F_parallel
\draw[-latex, thick] (P) -- (R) node[midway, below right] {$\vec{F_{\parallel}}$};
% Draw vector F_perpendicular
\draw[-latex, thick] (P) -- (S) node[midway, left] {$\vec{F_{\perp}}$};
% Draw point P
\fill (P) circle[radius=2pt] node[below right] {$P$};
% Draw point O
\fill (O) circle[radius=2pt] node[below left] {$O$};
% Draw dashed lines for projections
\draw[dashed] (S) -- (Q) -- (R);
% Draw arc for angle theta
\draw (0.5,0) arc[start angle=0,end angle=45,radius=0.5cm];
\node at (0.7,0.3) {$\theta$}; % Label for angle theta
% Draw the arc for angle phi
\draw (1,1) +(0:0.5cm) arc[start angle=0, end angle=\phhi, radius=0.5cm];
\node at (1.6,1.3) {$\phi$}; % Label for angle phi
% Draw arc for angle phi - theta
\draw (1,1) +(\thheta:1cm) arc[start angle=\thheta, end angle=\phhi, radius=1cm];
\node at (1.65,1.9) {$\alpha$}; % Label for angle phi - theta
% Draw dotted line from P to (2,1)
\draw[dotted] (P) -- (2,1);
% Draw dashed line from O to T
\draw[dashed] (O) -- (T);
% Draw dashed line from P to T
\draw[dashed] (P) -- (T);
\end{tikzpicture}
\end{document}
答案3
从 AndréC 的代码中,我们用或tkz-elements
定义点,然后进行绘图。tkz-euclide
tikz
代码
% !TeX program = lualatex
\documentclass{standalone}
\usepackage{tkz-elements}
\usepackage{tkz-euclide}
\begin{document}
\begin{tkzelements}
angle = math.pi/3
Fnorm = 3
--
z.O = point: new (0,0)
z.P = point: new (2,1)
--
-----------------------------
-- translation and rotation
V.v = vector: new (z.O,z.P)
V.w = Fnorm*V.v
-- in one step
z.F = z.P : rotation (angle,V.w.head : at (z.P))
--
-- or in two steps
--z.Pp = V.w.head : at (z.P)
-- rotation
--z.F = z.P : rotation (angle,z.Pp)
--------------------------------------
L.PF = line : new (z.P,z.F)
z.Q = L.PF : barycenter (6,4)
-- projection
z.Op = L.PF: projection(z.O)
L.OP = line : new (z.O,z.P)
z.Fp = L.OP: projection(z.F)
\end{tkzelements}
\tkzSetUpLabel[font=\footnotesize]
\begin{tikzpicture}
%\draw[help lines] (0,0)grid(8,8);
\tkzGetNodes
% points
\tkzDrawPoints(O,P,F,Q,O',F')
\tkzLabelPoints[below right](P)
\tkzLabelPoints[left](O,F,Q)
% line
\tkzDrawLine[dashed,add = 0 and 0.25](P,O')
\tkzDrawLine[dashed,add = 0 and 0.25](P,F')
% vecteurs
\tkzDrawSegments[-latex, thick, blue](P,F)
\tkzDrawSegments[-latex, thick, red](O,P)
\tkzDrawSegments[-latex, thick, orange](O,Q)
\tkzDrawSegments(O,O' F,F')
%
\tkzLabelSegment[blue,right](P,F){$\vec{F}$}
\tkzLabelSegment[red,above](O,P){$\vec{v}$}
\tkzLabelSegment[orange,above](O,Q){$\vec{r'}$}
\tkzLabelSegment[sloped,below](O,O'){$r\sin\theta$}
\tkzLabelSegment[right](F,F'){$F\sin\theta$}
% angle
\tkzMarkAngles[size = 0.4](O,P,O' F',P,F)
\tkzLabelAngle[pos=0.6](O,P,O'){$\theta$}
\tkzLabelAngle[pos=0.6](F',P,F){$\theta$}
% code AndréC
\node[inner sep=0pt] (Mo) at (barycentric cs:O=1,P=-.5 ,F=1){$M_o$};
\draw[->,very thick, blue] (Mo.south west)to[out=-90,in=-90,looseness=2](Mo.south east);
\end{tikzpicture}
\end{document}
编辑:
我tkz-elements
尝试使用 Matrix 类
% !TeX program = lualatex
\documentclass{article}
\usepackage{amsmath}
\usepackage{tkz-elements}
\usepackage{tkz-euclide}
\begin{document}
\begin{tkzelements}
z.P = point : new (2,1)
angle = math.pi/3
Fnorm = 3
-----------------------------
z.O = point : new (0,0)
V.OP = z.P.mtx : homogenization ()
--V.OP : print () tex.print('\\\\')
--
M = matrix : htm (angle , z.P.re , z.P.im)
--M : print () tex.print('\\\\')
S = matrix : square (3,Fnorm,0,0,0,Fnorm,0,0,0,1)
--S : print () tex.print('\\\\')
V.F = M * S * V.OP
--V.F : print () tex.print('\\\\')
z.F = get_htm_point(V.F)
--tex.print(display(z.F))
--------------------------------------
L.PF = line : new (z.P,z.F)
z.Q = L.PF : barycenter (6,4)
-- projection
z.Op = L.PF: projection(z.O)
L.OP = line : new (z.O,z.P)
z.Fp = L.OP: projection(z.F)
\end{tkzelements}
\tkzSetUpLabel[font=\footnotesize]
\begin{tikzpicture}[gridded]
\tkzGetNodes
% points
\tkzDrawPoints(O,P,F,Q,O',F')
\tkzLabelPoints[below right](P)
\tkzLabelPoints[left](O,F,Q)
% line
\tkzDrawLine[dashed,add = 0 and 0.25](P,O')
\tkzDrawLine[dashed,add = 0 and 0.25](P,F')
% vecteurs
\tkzDrawSegments[-latex, thick, blue](P,F)
\tkzDrawSegments[-latex, thick, red](O,P)
\tkzDrawSegments[-latex, thick, orange](O,Q)
\tkzDrawSegments(O,O' F,F')
%
\tkzLabelSegment[blue,right](P,F){$\vec{F}$}
\tkzLabelSegment[red,above](O,P){$\vec{v}$}
\tkzLabelSegment[orange,above](O,Q){$\vec{r'}$}
\tkzLabelSegment[sloped,below](O,O'){$r\sin\theta$}
\tkzLabelSegment[right](F,F'){$F\sin\theta$}
% angle
\tkzMarkAngles[size = 0.4](O,P,O' F',P,F)
\tkzLabelAngle[pos=0.6](O,P,O'){$\theta$}
\tkzLabelAngle[pos=0.6](F',P,F){$\theta$}
% code AndréC
\node[inner sep=0pt] (Mo) at (barycentric cs:O=1,P=-.5 ,F=1){$M_o$};
\draw[->,very thick, blue] (Mo.south west)to[out=-90,in=-90,looseness=2](Mo.south east);
\end{tikzpicture}
\end{document}