# Cylinder or tubes with different radius

I'm trying to generate a set of cylinders/tubes with different radii and colours.

In particular, I have this graph: {1 -> 2, 2 -> 3, 3 -> 4, 4 -> 5, 5 -> 1} with the following vertexes {0, 0, 0}, {0, 0, 10}, {10, 0, 10}, {10, 10, 0}, {5, 15, 10}.

Furthermore, I have a list of values b = {1, 3, 0.5, -1, -2} and I want to plot 5 tubes (one for each value) with a specified radius r1 if the related element of b is greater than zero, and r2 if it is <0. How can I do this? Also, I want to plot these tubes with a range of colours consistent with the vector b and a framed bar legend. Thanks.

q = {1, 3, 0.5, -1, -2};
Grafo = Graph[{1 <-> 2, 2 <-> 3, 3 <-> 4, 4 <-> 5, 5 <-> 1},
EdgeWeight -> q];
el = EdgeList[Grafo];
edgestylea =
ColorData[{"TemperatureMap", {Min[q], Max[q]}}][#]] & /@ q)];
Legended[Graph3D[Grafo, EdgeStyle -> edgestylea,
EdgeShapeFunction -> ({ColorFunction -> (ColorData[
"TemperatureMap", #] & /@ q),
Cylinder[#, If[# < 0, 0.1, 0.5] & /@ q]} &),
VertexLabels -> "Name",
VertexShapeFunction -> ({Yellow, Sphere[#, 1]} &),
VertexCoordinates -> {{0, 0, 0}, {0, 0, 10}, {10, 0, 10}, {10, 10,
0}, {5, 15, 10}}, AxesOrigin -> {0, 0, 0}, Axes -> True,
Ticks -> Automatic,
PlotLabel ->
Style[Framed["Tensegrity", RoundingRadius -> 10], 14, Black,
FontFamily -> "Times New Roman"], AxesLabel -> {x, y, z},
LabelStyle -> {FontFamily -> "Times New Roman"}],
Framed[BarLegend[{"TemperatureMap", {Min[q], Max[q]}},
LegendLabel -> "Internal force" ,
LabelStyle -> {FontFamily -> "Times New Roman"}],
RoundingRadius -> 10, FrameStyle -> GrayLevel[.5]]]


In my code, tubes with different radii consistent with b don't work! Someone can help me?

• What about the axes of these cylinders? Commented Apr 11, 2017 at 14:13
• I have this graph {1 [DirectedEdge] 2, 2 [DirectedEdge] 3, 3 [DirectedEdge] 4,4 [DirectedEdge] 5,5 [DirectedEdge] 6} with the following vertexes {0, 0, 0}, {0, 0, 10}, {10, 0, 10}, {10, 10, 0},{10, 10, 10},{10, 10, 20}. Commented Apr 11, 2017 at 15:27
• You should've mentioned that to begin with. Please edit your question to include this information. Commented Apr 11, 2017 at 15:34
• Sorry. I have this graph: {1 [DirectedEdge] 2, 2 [DirectedEdge] 3, 3 [DirectedEdge] 4,4 [DirectedEdge] 5,5 [DirectedEdge] 6} with the following vertexes {0, 0, 0}, {0, 0, 10}, {10, 0, 10}, {10, 10, 0},{10, 10, 10},{10, 10, 20}. I have a list of values b={1,3,0.5,-1,-2} and I want to plot 5 tubes (one for each value) with a specified radius r1 if the related element of b is greater than zero, and r2 if it is <0. How can I do this? Also, I want to plot the tubes with a range of colours consistent with the vector b and a framed bar legend. Thanks Commented Apr 12, 2017 at 7:15
• Please use the "edit" button at the bottom of your post, or click on this link, to add information to your post, instead of keeping it in the comments. Commented Apr 12, 2017 at 7:19

b = {1, 3, 0.5, -1, -2};

SeedRandom[3];

data = Transpose[
{Partition[RandomReal[1, {6, 3}], 2, 1], b}];

Graphics3D[Tube[#[[1]], If[#[[2]] < 0, 0.025, 0.05]] & /@ data]


or

r[x_] = Piecewise[{{0.025, x < 0}}, 0.05];

Graphics3D[Tube[#[[1]], r[#[[2]]]] & /@ data]


EDIT:

vertices = {{0, 0, 0}, {0, 0, 10}, {10, 0, 10}, {10, 10, 0}, {10, 10,
10}, {10, 10, 20}};