I'd like to draw a triangle (given the side lengths) with the sides colored separately.
I tried
Graphics[{FaceForm[Opacity[0]], EdgeForm[Blue], SSSTriangle[2, 2, 3]}]
giving:
But I want to color the edges separately, eg Blue, Green and Red.
I was going to do the same as george2079 (+1). I'll post it on account of having used a rather different programming style.
colorTriangle[Triangle[{pt1_, pt2_, pt3_}], {c1_, c2_, c3_}] := {
c1, Line[{pt1, pt2}],
c2, Line[{pt2, pt3}],
c3, Line[{pt3, pt1}]
}
Graphics[{
colorTriangle[SSSTriangle[2, 2, 3], {Red, Green, Blue}]
}]
Coloring it so that particular colors correspond to particular side lengths is more difficult, but here's one way:
SetAttributes[colorTriangle, HoldFirst]
colorTriangle[SSSTriangle[l1_, l2_, l3_], {c1_, c2_, c3_}] := Module[{allTriangles, wellOrderedQ, wellOrderedTriangles},
allTriangles = SSSTriangle[l1, l2, l3] /. Triangle[{pt1_, pt2_, pt3_}] :> Permutations[{
Line[{pt1, pt2}], Line[{pt2, pt3}], Line[{pt3, pt1}]
}];
wellOrderedQ = allTriangles /. {Line[{pt11_, pt12_}], Line[{pt21_, pt22_}], Line[{pt31_, pt32_}]} :> And[
Norm[pt11 - pt12] == l1,
Norm[pt21 - pt22] == l2,
Norm[pt31 - pt32] == l3
];
wellOrderedTriangles = Pick[allTriangles, wellOrderedQ, True];
Graphics@Riffle[{Red, Green, Blue}, #] & /@ wellOrderedTriangles
]
Since there aren't always one unique way to color a triangle in this fashion the result is a list of up to six triangles:
Just to make this more difficult than it has to be,
HighlightMesh[
DiscretizeGraphics@SSSTriangle[2, 2, 3], {Style[{2, 1}, White]}~
Join~({Style[{1, {#}}, Thick, {Red, Green, Blue}[[#]]] & /@
Range[3]})]
Style
None
works but here it breaks everything and White
saves the day,
$\endgroup$
Style[.., Opacity[0]]
but I couldn't get it to work..
$\endgroup$
Graphics[Transpose[{{Red, Green, Blue}, SSSTriangle[2, 2, 3] /.
Triangle[li_] :> Line /@ Partition[Append[li, li[[1]]], 2, 1] }]]
Graphics[Riffle[{Red, Green, Blue}, Map[Line, Partition[#, 2, 1, 1] & @@ SSSTriangle[2, 2, 3]]]]
$\endgroup$
Commented
Jun 28, 2016 at 23:30
Graph
? $\endgroup$