14

I guess this must be quite simple, but all I've tried didn't work so far. All I want is to get some triangles on the edge of a framework.

Something like this:

enter image description here

My code looks like this:

\documentclass[tikz]{standalone}
\usetikzlibrary{calc,decorations.markings}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[scale=1,inner sep=0pt,thick,dot/.style={draw,circle,minimum size=4pt},
put coord sys/.style={
decoration={markings,
mark= at position 0.5
with
{
\draw[-latex,ultra thin,blue!80!black] (2pt,2pt) -- ++(5mm,0) node[above right,rotate=\pgfdecoratedangle] {$\scriptstyle x$};
\draw[-latex,ultra thin,green!80!black] (2pt,2pt) -- ++(0,5mm) node[above right,rotate=\pgfdecoratedangle] {$\scriptstyle y$};
}
},
postaction=decorate}]

%\draw [help lines] (0,0) grid (3,4);
\node[dot] (2) at (0,0) [label={[label distance=1mm]270:2}] {};
\node[dot] (3) at (0,2) [label={[label distance=1mm]180:3}] {};
\node[dot] (1) at (0,4) [label={[label distance=1mm]90:1}] {};
\node[dot] (4) at (3,2) [label={[label distance=1mm]0:4}] {};
\node[dot] (5) at (2.5,4) [label={[label distance=1mm]45:5}] {};

%\draw[gray] ++(150:0.3) -- (0,0); 
%\draw[gray] ++(-150:0.3) -- (0,0); 
%\draw[gray] ++(180:0.3) -- (-.3,0); 

%\draw[gray] ++(0,4) -- (150:1); 
%\draw[gray] ++(-150:0.3) -- (0,4); 
%\draw[gray] ++(180:0.3) -- (-.3,4); 

%\draw  (2) -- (3) node [midway,sloped,above] {3};
%\draw  (3) -- (4) node [midway,above,sloped] {4};      
%\draw  (2) -- (4) node [midway,above,sloped] {6};      
%\draw  (3) -- (1) node [midway,above,sloped] {2};  
%\draw  (1) -- (5) node [midway,above,sloped] {1};  
%\draw  (3) -- (5) node [midway,above,sloped] {5};  
%\draw  (4) -- (5) node [midway,above,sloped] {7};      

\draw[put coord sys]   (2) -- (3);
\draw[put coord sys]   (3) -- (4);      
\draw[put coord sys]   (2) -- (4);  
\draw[put coord sys]   (1) -- (3);
\draw[put coord sys]   (1) -- (5);
\draw[put coord sys]   (4) -- (5);
\draw[put coord sys]   (3) -- (5);

\end{tikzpicture}

\end{document}

The "trick" with the \draw[gray] ++(150:0.3) -- (0,0); command doesn't work very well. In fact it doesn't work at all in this way :) Does anyone have any ideas how to get these triangles?

3
  • 3
    Have a look to the library tikz-mec: it contains some useful shapes for that. Jun 11, 2013 at 14:46
  • The ++ denotes a relative coordinate, relative to what coordinate should it be? Jun 11, 2013 at 14:52
  • Since you have some good responses that seem to answer your historical questions, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. Jul 12, 2013 at 14:41

2 Answers 2

12

The solution with the library tikz-mec (documentation only in Italian, but the examples and the shape details make it quite easy to be used):

\documentclass[tikz,png,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds,calc,decorations.markings,mec}
\begin{document}

\begin{tikzpicture}[scale=1,thick,dot/.style={draw,circle,minimum size=4pt,inner sep=0pt,},
put coord sys/.style={
decoration={markings,
mark= at position 0.5
with
{
\draw[-latex,ultra thin,blue!80!black] (2pt,2pt) -- ++(5mm,0) node[above right,rotate=\pgfdecoratedangle] {$\scriptstyle x$};
\draw[-latex,ultra thin,green!80!black] (2pt,2pt) -- ++(0,5mm) node[above right,rotate=\pgfdecoratedangle] {$\scriptstyle y$};
}
},
postaction=decorate}]


\draw [help lines] (0,0) grid (3,4);
\node[dot] (2) at (0,0) [label={[label distance=1mm]270:2}] {};
\node[dot] (3) at (0,2) [label={[label distance=1mm]180:3}] {};
\node[dot] (1) at (0,4) [label={[label distance=1mm]90:1}] {};
\node[dot] (4) at (3,2) [label={[label distance=1mm]0:4}] {};
\node[dot] (5) at (2.5,4) [label={[label distance=1mm]45:5}] {};

\node[draw,hinge,grounded=270,scale=0.85,transform shape] (hinge-1) at (0,4){};
\node[draw,hinge,grounded=270,scale=0.85,transform shape] (hinge-2) at (0,0){};

% with a loop is easier
\foreach \source/\dest in {2/3,3/4,2/4,1/3,1/5,4/5,3/5}
\draw[put coord sys]   (\source) -- (\dest);

% background addition
\begin{scope}[on background layer]
\fill[green!70!lime!15  ] 
 ($(hinge-1.south west)+(-0.5,1)$)--
 ($(hinge-1.south west)+(4.5,1)$)coordinate (x)--
 ($(x)+(0,-3)$)coordinate (y)--
 ($(y-|hinge-1.south east)-(0.5,0)$)--
 cycle;
\draw[green!70!lime!50]($(hinge-1.south west)+(-0.5,1)$)--
 ($(hinge-1.south west)+(4.5,1)$)coordinate (x)--
 ($(x)+(0,-3)$)coordinate (y)
 ($(hinge-1.south west)+(-0.5,1)$)--($(hinge-1.south west)-(0.5,2)$);
\end{scope}

\end{tikzpicture}

\end{document}

The result:

enter image description here

A foreach loop has been implemented to avoid writing some paths and it has been introduced a background to resemble the picture posted.

0
7

One way would be to define a macro for the triangle as follows:

\newcommand*{\Triangle}[2][]{%
    \draw [#1] #2 -- ++(-0.2,0.2) -- ++(0,-0.4) -- cycle;
}%

where #1 is any optional draw options, and #2 is the coordinate for the placement. The xshift=-1mm option was used to move the triangles to the left, so you can adjust that so the triangles are at the desired location.

enter image description here

Notes:

  • As Qrrbrbirlbel suggested, you could also use the node label to place the triangles such as:

    \Triangle[gray]{(2.west)}
    \Triangle[gray]{(1.center)}
    

Code:

\documentclass[tikz,border=2pt]{standalone}
\usetikzlibrary{calc,decorations.markings}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[scale=1,inner sep=0pt,thick,dot/.style={draw,circle,minimum size=4pt},
put coord sys/.style={
decoration={markings,
mark= at position 0.5
with
{
\draw[-latex,ultra thin,blue!80!black] (2pt,2pt) -- ++(5mm,0) node[above right,rotate=\pgfdecoratedangle] {$\scriptstyle x$};
\draw[-latex,ultra thin,green!80!black] (2pt,2pt) -- ++(0,5mm) node[above right,rotate=\pgfdecoratedangle] {$\scriptstyle y$};
}
},
postaction=decorate}]

%\draw [help lines] (0,0) grid (3,4);
\node[dot] (2) at (0,0) [label={[label distance=1mm]270:2}] {};
\node[dot] (3) at (0,2) [label={[label distance=1mm]180:3}] {};
\node[dot] (1) at (0,4) [label={[label distance=1mm]90:1}] {};
\node[dot] (4) at (3,2) [label={[label distance=1mm]0:4}] {};
\node[dot] (5) at (2.5,4) [label={[label distance=1mm]45:5}] {};

\newcommand*{\Triangle}[2][]{%
    \draw [#1] #2 -- ++(-0.2,0.2) -- ++(0,-0.4) -- cycle;
}%

\Triangle[gray,xshift=-1mm]{(0,0)}
%\draw[gray] ++(150:0.3) -- (0,0); 
%\draw[gray] ++(-150:0.3) -- (0,0); 
%\draw[gray] ++(180:0.3) -- (-.3,0); 


\Triangle[gray,xshift=-1mm]{(0,4)}
%\draw[gray] ++(0,4) -- (150:1); 
%\draw[gray] ++(-150:0.3) -- (0,4); 
%\draw[gray] ++(180:0.3) -- (-.3,4); 

%\draw  (2) -- (3) node [midway,sloped,above] {3};
%\draw  (3) -- (4) node [midway,above,sloped] {4};      
%\draw  (2) -- (4) node [midway,above,sloped] {6};      
%\draw  (3) -- (1) node [midway,above,sloped] {2};  
%\draw  (1) -- (5) node [midway,above,sloped] {1};  
%\draw  (3) -- (5) node [midway,above,sloped] {5};  
%\draw  (4) -- (5) node [midway,above,sloped] {7};      

\draw[put coord sys]   (2) -- (3);
\draw[put coord sys]   (3) -- (4);      
\draw[put coord sys]   (2) -- (4);  
\draw[put coord sys]   (1) -- (3);
\draw[put coord sys]   (1) -- (5);
\draw[put coord sys]   (4) -- (5);
\draw[put coord sys]   (3) -- (5);

\end{tikzpicture}

\end{document}
1
  • We could use the circle’s .west anchor to place the triangle (without repeating coordinates). Jun 11, 2013 at 15:33

You must log in to answer this question.

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