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 am trying to draw just the nodes (no sides) at the vertices of a regular hexagon. This answer should be easily modified to accomplish what I want, but I am such a novice that I have difficulty understanding the example. Ideally, each vertex would be a separate named node so that I can easily draw edges between them (I will be making several different graphs using these same nodes).

share|improve this question

6 Answers 6

up vote 7 down vote accepted

You can use the regular polygon shape from the shapes.geometric library, setting draw=none. Giving the node the name a, the vertices will be named a.corner 1, a.corner 2 etc.

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}

\begin{tikzpicture}
% create the node
\node[draw=none,minimum size=2cm,regular polygon,regular polygon sides=6] (a) {};

% draw a black dot in each vertex
\foreach \x in {1,2,...,6}
  \fill (a.corner \x) circle[radius=2pt];

\end{tikzpicture}
\end{document}
share|improve this answer
    
If I want to draw a regular plolygons with label at vertices. How I can do? –  minthao_2011 Jan 3 at 5:41
    
@minthao_2011 Place nodes at a.corner 1 etc. See for example tex.stackexchange.com/questions/141668/… –  Torbjørn T. Jan 3 at 10:31

Time to call \foreach. Of course, it is possible to use a lot of other tools.

\documentclass[]{report}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\foreach \a in {0,60,...,300} { %\a is the angle variable
\draw[fill] (\a:2cm) circle (1pt); % 2cm is the radius; 1pt is the radius of the small bullet
}
\end{tikzpicture}
\end{document}

enter image description here

Here are some other possible options, if you want to change colors.

\draw[line width=.7pt,blue,fill=yellow] (\a:1.5cm) circle (2pt);

enter image description here

share|improve this answer
    
I like the simplicity of your code, but is there a way to modify it so that I have names for each of the created nodes? –  Austin Mohr Jan 2 at 22:31

A recommended solution with PSTricks. Note that n-side polygon needs n+1 for the plotpoints.

\documentclass[pstricks]{standalone}
\usepackage{pst-node,pst-plot}
\begin{document}
\begin{pspicture}(-2,-2)(2,2)
    \curvepnodes[plotpoints=13]{0}{360}{2 t PtoC}{A}
    \psnline[linestyle=none,showpoints](0,\Anodecount){A}
\end{pspicture}
\end{document}

enter image description here

Note

\curvepnodes (implemented in pst-node) needs plotpoints (implemented in pst-plot). It seems to be a bit weird as IMHO, pst-node implementing \curvepnodes should load pst-plot internally to make plotpoints available.

Miscellaneous

\documentclass[pstricks,border=24pt]{standalone}
\usepackage{pst-node,pst-plot}
\psset{saveNodeCoors}
\begin{document}
\begin{pspicture}(-2,-2)(2,2)
    \curvepnodes[plotpoints=13]{0}{360}{2 t PtoC}{A}
    \psnline[showpoints](0,\Anodecount){A}
    \multido{\i=0+1}{\Anodecount}{\uput[!N-A\i.y N-A\i.x atan](A\i){$A_{\i}$}}
\end{pspicture}
\end{document}

enter image description here

share|improve this answer

Here is a PSTricks solution (with some extra features -- just remove the code not needed or outcomment it):

\documentclass{article}

\usepackage{
  pst-poly,
  pstricks-add
}
\usepackage[
%  locale = DE,
  round-mode = places,
  round-precision = 2
]{siunitx}

\ExplSyntaxOn
  \cs_new_eq:NN
    \calc
  \fp_eval:n
\ExplSyntaxOff

% calculations
\newcommand*\Angle{\calc{360/\sides}}
\newcommand*\sidelength{\calc{2*\radius*sin(pi/\sides)}}
\newcommand*\radiusI{\calc{\radius*cos(pi/\sides)}}
\newcommand*\areaI{\calc{pi*\radiusI^2}}%        not used
\newcommand*\areaC{\calc{pi*\radius^2}}%         not used
\newcommand*\areaRatio{\calc{cos(pi/\sides)^2}}% not used

\psset{dimen = middel}

\begin{document}

% constants
\newcommand*\sides{6}
\newcommand*\radius{3.5}

\begin{center}
\begin{pspicture}(-\radius,-\radius)(\radius,\radius)
  % centre
  \pnode(0,0){C}
  % regular polygon with dots at corners
  \rput(C){%
    \PstPolygon[
      PolyNbSides = \sides,
      unit = \radius
    ]
  }
 {\psset{linestyle = dashed}
  % inscribed circle
  \pscircle(C){\radiusI}
  % circumscribed circle
  \pscircle(C){\radius}}
  % dots with labels at the corners and lines from the centre to the corners
  \multido{\r = 0+\Angle, \i = 1+1}{\sides}{
    \psRelLine[
      angle = \r,
      linestyle = dotted
    ](C)(\radius,0){1}{A}
    \psdot[
      linecolor = red
    ](\radius;\r)
    \uput[\r](\radius;\r){$P_{\i}$}
  }
  % dot at centre
  \psdot[
    linecolor = blue!60
  ](C)
  % label position
  \pcline[
    linestyle = none,
    offset = 9pt
  ](C)(\radius,0)
  % label
  \ncput{$r = \num[round-mode = off]{\radius}$}
\end{pspicture}
\end{center}

\bigskip

\noindent Regular $\sides$-gon with side length~$s = \num{\sidelength}$.

\end{document}

output

share|improve this answer
1  
\psdot(\radius;\rA) –  Herbert Jan 3 at 12:22
    
Arrrh, yes. Thank you. I'll edit my answer accordingly. –  Svend Tveskæg Jan 3 at 12:24
1  
you can also do \degrees[\sides] and then simply \multido{\iA=0+1}{\sides}{...} –  Herbert Jan 3 at 12:35

Since someone added an tag, I'll go ahead and give an Asymptote solution. Note that the programming abilities of Asymptote have the following advantages:

  1. You can store all the points in an array, which makes it easy to reference them.
  2. It is easy and natural to create points for future reference without drawing them, if so desired.

The solution (with comments):

\documentclass[margin=10pt]{standalone}
\usepackage{asymptote}
\begin{document}
\begin{asy}
size(3cm,0);    // scale the final picture to be 3cm wide
pair[] vertices;    // an empty array of points
int n = 11;    // number of sides
real r = 1.0;    // radius of the circle in which the polygon is inscribed
// Add the vertices to the array:
for (real angle = 0; angle < 360; angle += 360/n) {
    // The `push` command adds its argument to the end of the array.
    vertices.push(r*dir(angle));  // r*dir(angle) gives the point with polar coordinates (r, angle).
}
// Draw the vertices:
for (pair vertex : vertices)
    dot(vertex);

// Draw a couple lines in respective colors:
draw(vertices[0] -- vertices[6], red);
draw(vertices[1] -- vertices[9], blue);
\end{asy}
\end{document}

The result:

enter image description here

share|improve this answer
    
Feel free to always add Asymptote solution to any questions related to plotting, drawing, diagramming, etc because it is allowed by law in this site. –  cyanide-based food Jan 5 at 21:33

For labels, you could try something like this based on the answer from Torbjørn T.:

\documentclass[]{report}
\usepackage{tikz}   
\begin{document}
\begin{tikzpicture}
    \foreach \a/\text in {0/A,60/B,120/C,180/D,240/E,300/F} 
    \draw[fill] (\a:2cm) circle (1pt) node[right] () {\text};
\end{tikzpicture}
\end{document}

which produces this

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.