如何绘制等正则图

如何绘制等正则图

我想要绘制下面的图表:

在此处输入图片描述

我能做这么多:

\documentclass[11pt]{scrartcl}
\usepackage{tkz-berge}

\begin{document}
\begin{tikzpicture}[scale=.5] 
\GraphInit[vstyle=Art] 
\SetGraphArtColor{red}{olive} 
\grPetersen[form=1,RA=5,RB=3]%
\end{tikzpicture}
\end{document}

这是我能画的:

在此处输入图片描述

问题 :借助以上代码,我可以绘制点,但我想以正方形的形式绘制四个点以及它们之间的边,见上图。

答案1

检查一下另一种方法Asymptote

在此处输入图片描述

%          qgr.tex
% run as
%
% pdflatex qgr.tex
% asy qgr-*.asy
% pdflatex qgr.tex
%
\documentclass[10pt,a4paper]{article}
\usepackage{lmodern}
\usepackage[inline]{asymptote}
\begin{asydef}
struct QuadGraph{
    pair a,b,c,d;
    pair center;
    guide s;
    real startNo;
    pen linePen, dotPen, idPen;
    void operator init(pair a,pair b,pair c,pair d){
        this.a=a; this.b=b; this.c=c; this.d=d; 
        center=(a+b+c+d)/4;
    }
    void draw(pen p=linePen){
        draw(s,p);
    }
    void dot(pen p=dotPen){
        dot(s,p,UnFill);
    }
    void label(pen p=idPen){
        label("$"+string(startNo)+"$",  a,1.5*unit(a-center),p);
        label("$"+string(startNo+1)+"$",b,1.5*unit(b-center),p);
        label("$"+string(startNo+2)+"$",c,1.5*unit(c-center),p);
        label("$"+string(startNo+3)+"$",d,1.5*unit(d-center),p);
    }

    void operator init(pair center, real side, real startNo
    ,pen linePen=currentpen, pen dotPen=currentpen, pen idPen=currentpen){
        this.center=center;
        this.startNo=startNo;
        this.linePen=linePen;
        this.dotPen=dotPen;
        this.idPen=idPen;
        a=center+( side/2, side/2);
        b=center+(-side/2, side/2);
        c=center+(-side/2,-side/2);
        d=center+( side/2,-side/2);
        s=a--b--c--d--cycle;
    }
}

QuadGraph operator*(transform tr, QuadGraph s){
    s.a=tr*s.a; s.b=tr*s.b; s.c=tr*s.c; s.d=tr*s.d;
    s.s=tr*s.s;
    s.center=tr*s.center;
    return s;
}

void joinOut(QuadGraph u, QuadGraph v, pen p=u.linePen){
    draw(u.b--v.a,p);
} 
void joinIn(QuadGraph u, QuadGraph v, pen p=u.linePen){
    draw(u.c--v.d,p);
} 

struct cycloQuad{
    int n;
    QuadGraph[] s;
    real side, R;
    pen linePen, dotPen, idPen;

    void makeCycle(){
        s=new QuadGraph[]; 
        pair u=(0,R);
        real phi;
        for(int i=0;i<n;++i){
            phi=i*360/n;
            s[i]=rotate(phi)*QuadGraph(u,side,startNo=i*4+1,linePen=linePen,dotPen=dotPen,idPen=idPen);
            s[i].draw();
        }
    }

    void draw(){
        for(int i=0;i<n;++i){
            joinOut(s[i],s[(i+1)%n]);
            joinIn (s[i],s[(i+2)%n]);
        }

        for(int i=0;i<n;++i){
            s[i].dot();
            s[i].label();
        }
    }

    void operator init(int n=5, real side=1, real R=12
    ,pen linePen=currentpen, pen dotPen=currentpen, pen idPen=currentpen
        ){
            assert(n>2 && side>0 && R>0);
            this.n=n; this.side=side; this.R=R;
            this.linePen=linePen;
            this.dotPen=dotPen;
            this.idPen=idPen;
            makeCycle();
            draw();
        }
    } 
\end{asydef}

\begin{document}

\begin{asy}
size(8cm);
cycloQuad(linePen=darkblue+1.2bp,idPen=deepred);
\end{asy}

\begin{asy}
size(9cm);
cycloQuad(n=7,side=1.6,R=17,linePen=orange+1.4bp, idPen=blue,dotPen=red+1bp);
\end{asy}

\end{document}

相关内容