[Tex/LaTex] Tikz new shape : how to access/define anchors

tikz-pgf

I would like to create some new shape in order to use it with tiKz. The problem I'm front facing is how to access edged of the newly created shapes.

So far I got this :

\documentclass[paper=a4,11pt,parskip=half,twoside]{scrartcl}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage[pdftex]{graphicx}

\usepackage{tikz}
\usepackage{circuitikz}
\usepackage{pgfplots}

\def\convEl{%
    ++(-.5,-.5) -- ++(1,0) -- ++(0,1) -- ++(-1,0) -- cycle
}

\def\convEm{%
    ++(0,0) circle (.5)
}

\def\convMe{%
    ++(-.5,-.5) -- ++(.5,1) -- ++(.5,-1) -- cycle
}

\def\accEn{%
    ++(-.5,-.5) -- ++(.5,0) -- ++(0,1) -- ++(-.5,0) -- cycle ++(0,-1) -- ++(.5,1)
}

\begin{document}

\begin{tikzpicture}
    \filldraw[draw=red,ultra thick,fill=orange] (0,0) \convEl node (a) {};
    \filldraw[draw=red,ultra thick,fill=orange] (2,0) \convEm node (b) {};
    \filldraw[draw=red,ultra thick,fill=orange] (4,0) \convMe;
    \filldraw[draw=red,ultra thick,fill=orange] (6,0) \accEn;
\end{tikzpicture}

\end{document}

Well maybe I should precise some more in comparison to the code provided. I want to access specific positions of my shapes, like bottom center and +30°/-30° on each side to connect arrows. Here is a little scheme of the behaviour expected. This is why I need to create / access some more anchors. If i draw a simple rectangle, I can do it, but with new/special shapes like the one I need…

Arrows connection

Best Answer

Using Spike's approach is for sure a possibility, but the shape to be defined is quite simple, so I think there's a simplest way. Credit should go to Jake's answer How to have a cross out rectangle in tikz?, because here I just adapted things.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\tikzset{
        orange square/.style={draw=red,ultra thick, fill=orange,%
        minimum width=1cm, minimum height=1cm},%
        orange circle/.style={circle,draw=red,ultra thick, fill=orange,minimum width=1cm},%
        orange triangle/.style={regular polygon, regular polygon sides=3,%
        draw=red,ultra thick, fill=orange,minimum height=1cm},%
        orange rectangle/.style={rectangle,draw=red,ultra thick,%
        fill=orange,minimum height=1cm,minimum width=0.5cm,append after command={                       
            (\tikzlastnode.north east) edge[draw=red,ultra thick,shorten >=1.75\pgflinewidth,
                shorten <=1.75\pgflinewidth,](\tikzlastnode.south west)
            }
        },%
}

\begin{document}
\begin{tikzpicture}[scale=1.75,transform shape]
\node[orange square] (a) at (0,0){};
\node[orange circle] (b) at (2,0){};
\node[orange triangle] (c) at (4,0){};
\node[orange rectangle] (d) at (6,0){};
\draw[->,>=stealth] (a.south) -- (b.west) (b.north) -- (c.north)-- (d.center);
\end{tikzpicture}
\end{document}

Result:

enter image description here


The edit of the question was very useful to better understand the request. In this case perhaps it is better to define a new shape, but that's Spike's domain: I provide you an alternative. Ok, it could be an alternative if one is used to the calc library.

The basic hint is that regular polygons define also corner anchors so, by taking them as reference, it is possible to access every position without defining a new shape.

The revised example:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,calc}

\tikzset{
        orange square/.style={regular polygon, regular polygon sides=4,%
        draw=red,ultra thick, fill=orange,minimum width=1.5cm},%
        orange triangle/.style={regular polygon, regular polygon sides=3,%
        draw=red,ultra thick, fill=orange,minimum height=1.5cm},%
        }

\begin{document}

\begin{tikzpicture}[scale=1.75,transform shape]
\node[orange square,] (e) at (0,-2){};
\node[orange triangle] (f) at (4,-2.165){};

% Display the anchors
\foreach \anchor/\placement in {corner 1/above, corner 2/above, corner 3/below, corner 4/below}
\draw[shift=(e.\anchor)] plot[mark=x] coordinates{(0,0)}node[\placement] {\tiny\texttt{(e.\anchor)}};

\foreach \anchor/\placement in {corner 1/above, corner 2/below, corner 3/below}
\draw[shift=(f.\anchor)] plot[mark=x] coordinates{(0,0)}node[\placement] {\tiny\texttt{(f.\anchor)}};

% Drawing the arrows    
\draw[-latex] ($(e.corner 3)!0.5!(e.corner 4)-(0,1)$)--($(e.corner 3)!0.5!(e.corner 4)$);
\draw[-latex] ($(e.corner 1)!0.2!(e.corner 4)$)--($(f.corner 1)!0.25!(f.corner 2)$);
\draw[-latex] ($(e.corner 1)!0.5!(e.corner 4)$)--($(f.corner 1)!0.525!(f.corner 2)$);
\draw[-latex] ($(e.corner 1)!0.8!(e.corner 4)$)--($(f.corner 1)!0.8!(f.corner 2)$);
\end{tikzpicture}
\end{document}

Result:

enter image description here