ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 24 Apr 2013 12:00:50 -0500Rotating positions of vertices (graph theory)http://ask.sagemath.org/question/9388/rotating-positions-of-vertices-graph-theory/Okay, in a [previous question](http://ask.sagemath.org/question/1757/strategies-for-drawing-good-graphs-graph-theory), 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!Thu, 04 Oct 2012 10:09:56 -0500http://ask.sagemath.org/question/9388/rotating-positions-of-vertices-graph-theory/Answer by fidbc for <p>Okay, in a <a href="http://ask.sagemath.org/question/1757/strategies-for-drawing-good-graphs-graph-theory">previous question</a>, 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.</p>
<p>One way I came up with, that doesn't really work, is to </p>
<pre><code>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)
</code></pre>
<p>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!</p>
http://ask.sagemath.org/question/9388/rotating-positions-of-vertices-graph-theory/?answer=14839#post-id-14839Graph 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]))Wed, 24 Apr 2013 12:00:50 -0500http://ask.sagemath.org/question/9388/rotating-positions-of-vertices-graph-theory/?answer=14839#post-id-14839