4

I googled a lot but I did not find anything relevant. How to create in Tikz the following figure?

https://fr.wikipedia.org/wiki/Moment_d%27une_force#/media/Fichier:Momento_de_uma_for%C3%A7a..png

Here is what I did so far.

\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}

enter image description here

How can I get easily the projections along the direction of vector OP and normal to it, the moment arm, and the curly vector representing the moment vector?

Thank you very much for any help.

3 Answers 3

8

Update

To obtain a PF length 3 times longer than OP, I use the let operation.

\path let  \p1=($(P)-(O)$),
            \n1 = {veclen(\x1,\y1)},
            in 
(O)--(P)--([turn]\angle:\n1*\Fnorm])coordinate (F);

I've changed the way you defined the coordinates to simplify the calculations. And I've made a lot of changes, so I haven't got time to explain them all. I'll let you have a look at the code, and if there's anything you don't understand, just say so and I'll explain.

\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}

enter image description here

2
  • 1
    Wow! Thank you very much for this beautiful draw. I've poste also myself an answer. I spend a lot time trying to figure out the associated angles, vectors, distances. Your solution is clear. I do not have any particular remark. If you have I would appreciate any feedback on how to improve my code. Merci!
    – Dimitris
    Apr 18 at 17:25
  • I've updated the answer so that the PF length is 3 times that of OP. To do this, I use the let operation.
    – AndréC
    Apr 19 at 8:39
5

I post my updated code as an answer. Far from the wiki image but still it can be useful for others.

\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}

Moment of force

2
  • 3
    I have no particular comments on your code. You have a mathematical approach, I have a purely graphical one. The main thing is to make your code readable so that years from now, when you read your code, you won't be wondering why you did what you did. I advise you to comment on the reason for your calculations, explaining them as the excellent skillmon has done here: tex.stackexchange.com/a/502923/138900
    – AndréC
    Apr 18 at 17:47
  • 1
    I‘d also add a screenshot of your codes result.
    – MS-SPO
    Apr 18 at 17:50
2

from AndréC's code with tkz-elements, we define the points with tkz-euclide or tikz, we carry out the plots.

The code

% !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}

EDIT: With tkz-elements I tried to use the Matrix class

    % !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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .