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).
7 Answers
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}
-
3If I want to draw a regular plolygons with label at vertices. How I can do? Jan 3, 2014 at 5:41
-
@minthao_2011 Place nodes at
a.corner 1
etc. See for example tex.stackexchange.com/questions/141668/… Jan 3, 2014 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}
Here are some other possible options, if you want to change colors.
\draw[line width=.7pt,blue,fill=yellow] (\a:1.5cm) circle (2pt);
-
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? Jan 2, 2014 at 22:31
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}
\usepackage{xfp}
% calculations
\newcommand*\Angle{\fpeval{360/\sides}}
\newcommand*\sidelength{\fpeval{2*\radius*sin(pi/\sides)}}
\newcommand*\radiusI{\fpeval{\radius*cos(pi/\sides)}}
%\newcommand*\areaI{\fpeval{pi*\radiusI^2}}
%\newcommand*\areaC{\fpeval{pi*\radius^2}}
%\newcommand*\areaRatio{\fpeval{cos(pi/\sides)^2}}
\psset{dimen = m}
\begin{document}
% constants
\def\sides{6}
\def\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}
-
1
\psdot(\radius;\rA)
– user2478Jan 3, 2014 at 12:22 -
-
1you can also do
\degrees[\sides]
and then simply\multido{\iA=0+1}{\sides}{...}
– user2478Jan 3, 2014 at 12:35
Since someone added an asymptote tag, I'll go ahead and give an Asymptote solution. Note that the programming abilities of Asymptote have the following advantages:
- You can store all the points in an array, which makes it easy to reference them.
- 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:
-
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. Jan 5, 2014 at 21:33
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}
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}
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
I use tkz-euclide
with code
\documentclass[border=1.5mm,12pt]{standalone}
%\usepackage[utf8]{inputenc}
\usepackage{fouriernc}
\usepackage{tkz-euclide,amsmath}
\usetkzobj{all}
\tikzset{hidden/.style = {thick, dashed}}
\begin{document}
\begin{tikzpicture}
\tkzDefPoint(0,0){O}\tkzDefPoint(2,0){A}
\tkzDefPointsBy[rotation=center O angle 360/6](A,B,C,D,E){B,C,D,E,F}
\tkzDrawPoints[fill =black,size=10,color=black](A,B,C,D,E,F)
\tkzLabelPoints[above](B,C)
\tkzLabelPoints[right](A)
\tkzLabelPoints[left](D)
\tkzLabelPoints[below](E,F)
\tkzDrawPolygon[ultra thick](A,B,C,D,E,F)
\end{tikzpicture}
\end{document}