# How to have a different style for edges of a triangle

Consider the following triangle.

Graphics[{EdgeForm[Directive[Thick, Red]], Gray, Triangle[]}]

The EdgeForm is defining the edges style for all three edges of the triangle.

How can I give separate Directive for each edge of the Triangle.

• By using Line for each edge of the triangle separately. – Henrik Schumacher Feb 19 at 15:57
• You mean have three separate Line objects that connect to give an illusion of a Triangle? – user13892 Feb 19 at 15:59
• Yes. And in order to obtain a filled triangle, you may use a true Triangle object with specified FaceForm and EdgeForm[None]; the Line objects have to appear in the list afterwards (so that the Line objects are plotted after the Triangle object). – Henrik Schumacher Feb 19 at 16:03

You can construct lines from the input Triangle and add them to your list of primitives in Graphics:

ClearAll[triangleToLines]
triangleToLines[Triangle[a_]] := Line /@ Partition[Append[a, a[[1]]], 2, 1]


Examples:

Graphics[{EdgeForm[Directive[Thick]], Gray, Triangle[],
Opacity[.5], CapForm["Round"], Thickness[.05],


Graphics[{EdgeForm[Directive[Thick]], Gray, Triangle[],
Opacity[.5], CapForm["Round"], Thickness[.05],
MapThread[# /. Line[x_] :> Line[x, VertexColors -> #2] &, {triangleToLines[
Triangle[]] , Partition[{Red, Green, Blue}, 2, 1, 1]}]}]


Graphics[{EdgeForm[Directive[Thick]], Gray, Triangle[{{0, 0}, {1, 1}, {2, 0}}],
Opacity[.5], CapForm["Round"], Thickness[.05],
Thread[{{Red, Green, Blue}, triangleToLines[Triangle[{{0, 0}, {1, 1}, {2, 0}}]] }]}]


t3d = Triangle[{{0, 0, 0}, {1, 0, 0}, {0, 1, 1}}];
Graphics3D[{EdgeForm[Directive[Thick]], Gray, t3d,
Opacity[.5], CapForm["Round"], Thickness[.05],
Thread[{{Red, Green, Blue}, Tube[#, .1] & @@@ triangleToLines[t3d] }]}]


• +1 The definition for triangleToLines[Triangle[]] is unnecessary. It is handled by the general case. – Bob Hanlon Feb 20 at 1:52
• Thank you @BobHanlon. Excellent point!! – kglr Feb 20 at 1:54