Application Center - Maplesoft

App Preview:

A Drawing Routine for Symmetric Graphs in the Plane

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

graphDrawing.mws

A Drawing Routine for Symmetric Graphs in the Plane

by Prof. Stephen Locke
Florida Atlantic University

This Maple application provides a routine for drawing some interesting symmetric graphs in the plane.

>    restart;

>    with(plots):

>    with(LinearAlgebra):

Warning, the name changecoords has been redefined

The routine here can be used to draw a picture of a small graph. I like to specify where the vertices are to be located, rather than have the computer decide for me. It would be easy for the user to add an "elastics-springs" routine to place the vertices.

>    GraphPlot := proc( A, x, y, radius)
  local i, j, Vertices, E, Edges, r, ll, lb, ub, tx;

  r := LinearAlgebra[RowDimension](A):

  Vertices := seq( plottools[circle]( [x[i],y[i]], radius, color=blue ), i=1..r):

  E := {}:
  for i from 1 to r-1 do
    for j from i+1 to r do
      if A[i,j] <> 0 then
        ll :=evalf(sqrt( (x[i]-x[j])^2 + (y[i]-y[j])^2)):
        if(ll<0.001) then print(`bad edge `,i,j): end if:       
        lb := radius/ll:
        ub := (ll-radius)/ll:
        E := E union {[x[i]+tx*(x[j]-x[i]),y[i]+tx*(y[j]-y[i]),tx=lb..ub]}:
      end if:
    end do:
  end do:

  Edges := plot(E, color=black, thickness=3):

  plots[display]( Vertices, Edges,
                  scaling=constrained, axes=none);
end proc:

>    s := {seq((i,i+1)=1,i=1..9),
      seq((i,i+10)=1,i=1..9),
      seq((i+10,11+((i+1) mod 10))=1,i=1..10),
      (10,1)=1,(10,20)=1}:

>    A := Matrix(20, 20, s):

>    A := A + Transpose(A):

>    x := Vector(20):  
y := Vector(20):  

>    s := 0.7:

>    for i from 1 to 10 do
  x[i]:=cos(i*Pi/5):
  y[i]:=sin(i*Pi/5):
  x[10+i]:=s*cos(i*Pi/5):
  y[10+i]:=s*sin(i*Pi/5):
end do:

>    GraphPlot(A,x,y,.03);

[Maple Plot]

>    s := {seq((i,i+1)=1,i=1..3),
      seq((i,i+4)=1,i=1..3),
      seq((i+4,5+(i mod 4))=1,i=1..4),
      (4,1)=1,(4,8)=1}:

>    A := Matrix(8, 8, s):

>    A := A + Transpose(A):

>    x := Vector(8):  
y := Vector(8):  

>    s := 0.5:

>    for i from 1 to 4 do
  x[i]:=cos(i*Pi/2):
  y[i]:=sin(i*Pi/2):
  x[4+i]:=s*cos(i*Pi/2):
  y[4+i]:=s*sin(i*Pi/2):
end do:

>    GraphPlot(A,x,y,.03);

[Maple Plot]

>    s := {(1,2)=1, (1,3)=1, (1,5)=1, (1,6)=1, (2,3)=1, (2,4)=1, (2,6)=1, (3,4)=1, (3,5)=1,
      (4,5)=1, (4,6)=1, (5,6)=1}:

>    A := Matrix(6, 6, s):

>    A := A + Transpose(A):

>    x := Vector(6):  
y := Vector(6):  

>    s := 0.3:

>    for i from 1 to 3 do
  x[2*i-1]:=cos((2*i-1)*Pi/3):
  y[2*i-1]:=sin((2*i-1)*Pi/3):
  x[2*i]:=s*cos(2*i*Pi/3):
  y[2*i]:=s*sin(2*i*Pi/3):
end do:

>    GraphPlot(A,x,y,.03);

[Maple Plot]

>    s := {(1,2)=1, (1,3)=1, (1,4)=1, (1,5)=1, (1,9)=1,
      (2,3)=1, (2,5)=1, (2,6)=1, (2,7)=1,
      (3,7)=1, (3,8)=1, (3,9)=1,
      (4,5)=1, (4,9)=1, (4,10)=1, (4,11)=1,
      (5,6)=1, (5,11)=1,
      (6,7)=1, (6,11)=1, (6,12)=1,
      (7,8)=1, (7,12)=1,
      (8,9)=1, (8,10)=1, (8,12)=1,
      (9,10)=1,
      (10,11)=1, (10,12)=1,
      (11,12)=1}:

>    A := Matrix(12, 12, s):

>    A := A + Transpose(A):

>    x := Vector(12):  
y := Vector(12):  

>    s := 0.4: t := 0.3: u := 0.2:

>    x[1]:=cos(1*Pi/3):   y[1]:=sin(1*Pi/3):   x[2]:=cos(3*Pi/3):    y[2]:=sin(3*Pi/3):

>    x[3]:=cos(5*Pi/3):   y[3]:=sin(5*Pi/3):   x[4]:=t*cos(1*Pi/3):  y[4]:=t*sin(1*Pi/3):

>    x[5]:=s*cos(2*Pi/3): y[5]:=s*sin(2*Pi/3): x[6]:=t*cos(3*Pi/3):  y[6]:=t*sin(3*Pi/3):

>    x[7]:=s*cos(4*Pi/3): y[7]:=s*sin(4*Pi/3): x[8]:=t*cos(5*Pi/3):  y[8]:=t*sin(5*Pi/3):

>    x[9]:=s*cos(6*Pi/3): y[9]:=s*sin(6*Pi/3): x[10]:=u*cos(6*Pi/3): y[10]:=u*sin(6*Pi/3):

>    x[11]:=u*cos(2*Pi/3):y[11]:=u*sin(2*Pi/3):x[12]:=u*cos(4*Pi/3): y[12]:=u*sin(4*Pi/3):

>    GraphPlot(A,x,y,.03);

[Maple Plot]

>   

>   

>   

>   

>   

>