-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction_rotateGraph.txt
22 lines (16 loc) · 9.23 KB
/
function_rotateGraph.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
rotateGraph[graph_, angle_] :=
Module[{edges, positions, rotatedPositions, rotationMatrix},
(* Define the rotation matrix *)
rotationMatrix[θ_] := {{Cos[θ], Sin[θ]}, {-Sin[θ], Cos[θ]}};
(* Get the edges of the graph *)
edges = EdgeList[graph];
(* Get the current vertex coordinates of the graph using GraphEmbedding *)
positions = GraphEmbedding[graph];
(* Apply the rotation to each vertex's coordinates *)
rotatedPositions = (rotationMatrix[angle] . #) & /@ positions;
(* Return the graph with the rotated vertex coordinates *)
Graph[graph, VertexCoordinates -> rotatedPositions]
]
(*example*)
g=Graph[{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}, {1 <-> 2, 1 <-> 3, 1 <-> 4, 1 <-> 5, 2 <-> 3, 2 <-> 6, 2 <-> 7, 3 <-> 8, 3 <-> 9, 4 <-> 9, 4 <-> 10, 4 <-> 11, 5 <-> 6, 5 <-> 11, 5 <-> 12, 6 <-> 13, 6 <-> 14, 7 <-> 8, 7 <-> 14, 7 <-> 15, 8 <-> 16, 8 <-> 17, 9 <-> 17, 9 <-> 18, 10 <-> 11, 10 <-> 18, 10 <-> 19, 11 <-> 20, 12 <-> 13, 12 <-> 20, 12 <-> 21, 13 <-> 14, 13 <-> 22, 14 <-> 23, 15 <-> 16, 15 <-> 23, 15 <-> 24, 16 <-> 24, 16 <-> 25, 17 <-> 18, 17 <-> 25, 18 <-> 26, 19 <-> 20, 19 <-> 26, 19 <-> 27, 20 <-> 27, 21 <-> 22, 21 <-> 27, 21 <-> 28, 22 <-> 23, 22 <-> 29, 23 <-> 29, 24 <-> 29, 24 <-> 30, 25 <-> 26, 25 <-> 30, 26 <-> 31, 27 <-> 31, 28 <-> 29, 28 <-> 30, 28 <-> 31, 30 <-> 31}, {FormatType -> TraditionalForm, GraphHighlight -> {18, 22, 27, UndirectedEdge[15, 16], 28, 3, 10, UndirectedEdge[15, 24], UndirectedEdge[30, 31], UndirectedEdge[3, 2], 14, 6, 9, UndirectedEdge[19, 27], 2, UndirectedEdge[14, 13], 20, UndirectedEdge[1, 3], 11, 30, UndirectedEdge[28, 30], UndirectedEdge[9, 17], UndirectedEdge[22, 23], UndirectedEdge[4, 11], UndirectedEdge[6, 14], UndirectedEdge[19, 20], 1, UndirectedEdge[11, 10], 24, UndirectedEdge[18, 17], 17, UndirectedEdge[20, 27], UndirectedEdge[9, 18], 19, 15, 29, UndirectedEdge[16, 24], 4, 13, 16, UndirectedEdge[4, 10], 23, UndirectedEdge[23, 29], UndirectedEdge[28, 31], 31, UndirectedEdge[6, 13], UndirectedEdge[22, 29], UndirectedEdge[1, 2]}, GraphHighlightStyle -> {UndirectedEdge[4, 11] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[14, 13] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, 28 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[18, 17] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, 27 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, 11 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, 31 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[20, 27] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, 1 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, 14 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[19, 27] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, 20 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, 15 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[3, 2] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[1, 2] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, 22 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, 29 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[28, 30] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[9, 18] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[15, 24] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[9, 17] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, 6 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, 17 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[6, 14] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[1, 3] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[22, 29] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, 9 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[22, 23] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, 30 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[16, 24] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[4, 10] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, 13 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[28, 31] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[11, 10] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, 19 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, 2 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[30, 31] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, 18 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[19, 20] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[6, 13] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, 16 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, 24 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[23, 29] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}, 3 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, 4 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, 10 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, 23 -> {VertexStyle -> Directive[Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[Opacity[1], RGBColor[0, 0, 1], Thickness[Large]]]]}, UndirectedEdge[15, 16] -> {EdgeStyle -> Directive[Opacity[1], Thickness[0.005], RGBColor[0, 0, 1], EdgeForm[Directive[RGBColor[0, 0, 1], Thickness[Large]]]]}}, GraphLayout -> "TutteEmbedding", ImageSize -> {495.200000000001, Automatic}}]
rotateGraph[g, 45 Degree]