# Rotating positions of vertices (graph theory)

Okay, in a previous question, I had asked how to draw nice graphs (graph theory). The answer was that the graph editor doesn't work any more so it's difficult, but a method was given that gave pretty good results. Using the techniques from that answer, I have the graph I want, except for the fact that I really want the picture rotated maybe 10 degrees counterclockwise. I'm trying to figure out how to do that.

One way I came up with, that doesn't really work, is to

angle = N(pi/18,50) #10 degrees
rot_matrix = matrix([[cos(angle), -sin(angle)],[sin(angle), cos(angle)]])

# The positions I have that need to be rotated
vert_pos={1: [0.8673592336550745, 0.8429750421487532], 2: [1.9428093163339426,
-0.8431329679383224], 3: [1.4051376567035885, 0.00014406801556917983],
4: [0.5620360593167806, -0.5378052476892125], 5: [2.2481442372671223,
0.5376447760675024], 6: [2.242709991911365, -0.18522591255842943], 7:
[1.219908082104656, -0.8375102818085887], 8: [1.5903441316845326,
0.8377000019696369], 9: [0.5674977685525984, 0.18521052179309053]}

# Hopefully, the positions that work perfectly!
new_pos = {}
for i in vert_pos: new_pos[i] = rot_matrix * i

graph_plot = g.plot(talk=True, pos=new_pos)


The problem is, instead of having an ordered pair, now I have a 2 by 1 matrix for each i. Is this method worthless? Or can it be saved? Or, I don't really care about using this method specifically, any one that works will do!

edit retag close merge delete

Sort by » oldest newest most voted Graph editor seems to be working in sage 5.8 :)

The code you posted seems to work, except that you need to multiply rot_matrix by vector(vert_pos[i]). If you really insist on having tuples instead of matrices for the positions you can try changing

for i in vert_pos:
new_pos[i] = rot_matrix * vector(vert_pos[i])


to

for i in vert_pos:
new_pos[i] = tuple(rot_matrix * vector(vert_pos[i]))

more