Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have six lines emanating from a single point or six lines converging to a single point. Is there any simple way to write one line code in TikZ?

Basically, I have this code and I want to reduce the number of lines. I know I can use options for node

\documentclass{article}
\usepackage{pgfplots,tikz}
\usetikzlibrary{
  positioning,
  snakes,
  shapes,
  shadows
}
\begin{document}
\begin{tikzpicture}
\draw[fill=green!80] (0,0) circle (1);
\draw[fill=black](0,0)circle(0.5ex) node[right]{Access Point};
\draw[fill=blue!50] (1,3)--+(300:5) arc (300:330:5)--cycle;
\draw(3,1.5) node{Main Beam};
\draw[fill=black](1,3) circle(0.5ex) node[above]{Base Station};
\node[draw,star,fill=black,scale=0.3] at (4,0){};
\draw(4,0) node[above] {Cell User};
\draw(55:0.5) node[rectangle,fill=black,scale=0.5](a){};
\draw(120:0.8) node[rectangle,fill=black,scale=0.5](b){};
\draw(210:0.7) node[rectangle,fill=black,scale=0.5](c){};
\draw(235:0.3) node[rectangle,fill=black,scale=0.5](d){};
\draw(275:0.8) node[rectangle,fill=black,scale=0.5](e){};
\draw(320:0.6) node[rectangle,fill=black,scale=0.5](f){};
\draw[-,dashed](-2,0)--++(a);
\draw[-,dashed](-2,0)--++(b);
\draw[-,dashed](-2,0)--++(c);
\draw[-,dashed](-2,0)--++(d);
\draw[-,dashed](-2,0)--++(e);
\draw[-,dashed](-2,0)--++(f);
\node[left] at(-2,0){Sensing Devices};
\end{tikzpicture}
\end{document}
share|improve this question
    
Welcome to TeX.SE. –  Peter Grill Jun 15 '12 at 19:53

2 Answers 2

up vote 13 down vote accepted

You can use a \foreach loop:

\foreach \Point/\Angle\Dist in {a/55/0.5,b/120/0.8,c/210/0.7,d/235/0.3,e/275/0.8,f/320/0.6} {%
    \draw(\Angle:\Dist) node[rectangle,fill=black,scale=0.5](\Point){};
    \draw[-,dashed](-2,0)--++(\Point);
}

enter image description here

Note:

  • In the MWE below I have deleted the portion of the picture that was not related to the question.

Code:

\documentclass{article}
\usepackage{pgfplots,tikz}
\usetikzlibrary{
  positioning,
  snakes,
  shapes,
  shadows
}
\begin{document}
\begin{tikzpicture}
\draw[fill=green!80] (0,0) circle (1);
\draw[fill=black](0,0)circle(0.5ex) node[right]{Access Point};

\foreach \Point/\Angle\Dist in {a/55/0.5,b/120/0.8,c/210/0.7,d/235/0.3,e/275/0.8,f/320/0.6} {%
    \draw(\Angle:\Dist) node[rectangle,fill=black,scale=0.5](\Point){};
    \draw[-,dashed](-2,0)--++(\Point);
}

\node[left] at(-2,0){Sensing Devices};
\end{tikzpicture}
\end{document}
share|improve this answer

you can reduce the code a little more. You can remove the names of the nodes and draw directly the edges

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[fill=green!80] (0,0) circle (1);
\draw[fill=black](0,0)circle(0.5ex) node[right]{Access Point};
\foreach \Angle\Dist in {55/0.5,120/0.8,210/0.7,235/0.3,275/0.8,320/0.6} {%
    \draw[-,dashed](-2,0)--(\Angle:\Dist) coordinate[rectangle,fill=black,inner sep=0.17em];
}
\node[left] at(-2,0){Sensing Devices};
\end{tikzpicture}
\end{document} 

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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