3

I am drawing some force diagrams, and would really like the ability to draw a small right triangle on a line, like in the snapshot below.

Right now I'm drawing my force vectors like so:

\draw[force,->] (O) -- (C) 
    node[below] {$F_1 = \SI{850}{\newton}$};

I tried to create another node node[midway] (midPoint) {}, then \draw (midPoint) -- ++(0,-3mm) -- ++(4mm,0) however, there is some ugly gap between the vector and this tiny triangle.

Is there a library that I don't know about to help create annotations like these? Or perhaps more idiomatic tikz way of doing this?

Right triangle on a line

Thanks for your time!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

EDIT: So I repurposed a tangentially related answer (Triangle as constraints in structural engineering) to some extent:

RightAngle/.style=
{
    decoration={
        markings,
        mark=at position 0.5 with {
        \draw[-, thin] (0,0) -- (0,-3mm) 
            node[midway, left] {\tiny 3};
        \draw[-,thin] (0,-3mm) -- (4mm, 0) 
            node[midway, below] {\tiny 4};
        }
    },
    postaction=decorate
}

\draw[force,->, RightAngle] (O) -- (C) 
    node[below right] {$F_1 = \SI{850}{\newton}$};

Which gets me almost there! However I'm still missing something to do with the new local coordinate system. How do I make that 3 leg come straight down (relative to the standard coordinate system)?

Skewed triangle

  • 1
    Welcome to TeX.SE. While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill May 20 '14 at 6:10
3

WIth tikz here is one way to do it: select the start point and end point on the vector itself:

\coordinate (Start Point) at ($(O)!0.3!(C)$);
\coordinate (End Point)   at ($(O)!0.5!(C)$);

In the above the (Start Point) is 0.3 along the length, and the (End Point) is at 0.5 along the path, and use |- to connect them which draws a vertical line followed by a horizontal line:

enter image description here

Code:

\documentclass{article}
\usepackage{siunitx}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
    \coordinate (O) at (0,0);
    \coordinate (B) at (3,4);
    \coordinate (C) at (3,-2);

    \draw[ultra thick, red, -latex] (O) -- (B) node[above] {$F_1 = \SI{950}{\newton}$};
    \coordinate (Start Point) at ($(O)!0.3!(B)$);
    \coordinate (End Point)   at ($(O)!0.5!(B)$);
    \draw [red] (Start Point) |- (End Point);

    \draw[ultra thick, blue, -latex] (O) -- (C) node[below] {$F_1 = \SI{850}{\newton}$};
    \coordinate (Start Point) at ($(O)!0.3!(C)$);
    \coordinate (End Point)   at ($(O)!0.5!(C)$);
    \draw [blue] (Start Point) |- (End Point);
\end{tikzpicture}
\end{document}
  • The point C should be (4,-3) to make it have a consistent slope as described by the slope triangle. In addition, End Point must be $(O)!0.8!(C)$. – kiss my armpit May 20 '14 at 6:28
  • @MoneyOrientedProgrammer: Thanks, but it is not clear to me that that is the requirement. The 3-4-5 triangle won't fit many vectors so the ability to draw that is rather limited. I went with a general purpose method which will draw a right triangle on any vector.. – Peter Grill May 20 '14 at 6:37
0

Just for typing exercise with PSTricks.

Option 1

\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{pst-eucl}
\psset
{
    PointName=none,
    PointSymbol=none,
    shortput=nab,
    linewidth=2pt,
    linecap=1,
}
\usepackage{siunitx}
\begin{document}
\begin{pspicture}(5,-4)
    \pstGeonode
        {A}
        (4,-3){B}   
        ([nodesep=1]{B}A){A'}
        ([offset=-30pt]A'){C}
        ([nodesep=40pt]C){B'}
    \ncline[linestyle=none]{A'}{B'}^{5}
    \ncline[linecolor=gray]{A'}{C}_{3}
    \ncline[linecolor=gray]{C}{B'}_{4}
    \ncline{->}{A}{B}
    \uput[-90](B){$F_1=\SI{850}{\newton}$}
\end{pspicture}
\end{document}

Option 2

\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{pst-eucl}
\psset
{
    PointName=none,
    PointSymbol=none,
    shortput=nab,
    linewidth=2pt,
    linecap=1,
}
\usepackage{siunitx}
\begin{document}
\begin{pspicture}(5,-4)
    \pstGeonode{A}(4,-3){B}([nodesep=1]{B}A){A'}([nodesep=50pt]{B}A'){B'}(A'|B'){C}
    \ncline[linestyle=none]{A'}{B'}^{5}
    \ncline[linecolor=gray]{A'}{C}_{3}
    \ncline[linecolor=gray]{C}{B'}_{4}
    \ncline{->}{A}{B}
    \uput[-90](B){$F_1=\SI{850}{\newton}$}
\end{pspicture}
\end{document}

enter image description here

0

Another PSTricks solution. Run with xelatex:

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-node}
\begin{document}

\begin{pspicture}[shortput=nab,arrowscale=1.5](5,-4)
\pnodes(0,0){A}(4,-3){B}   
\pcline[linewidth=1.5pt,arrows=->](A)(B)
\psLNode(A)(B){0.15}{C} \psLNode(A)(B){0.4}{D}
\pcline[linewidth=0.5pt](C)(C|D)_3 
\pcline[linewidth=0.5pt](C|D)(D)_4
\pcline[linestyle=none](C)(D)^5
\uput[-90](B){$F_1=850\,\textrm{N}$}
\end{pspicture}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.