# Labeling triangle edges in Mathematica 10

Mathematica 10 introduced lots of new geometry related functions, and one of these is SSSTriangle which creates a triangle graphic given the three side lengths. Is it possible however to label the side lengths to achieve something like this

-
If we can figure out how to convert this to a MeshRegion, then this is possible with HighlightMesh. – Szabolcs Jul 12 '14 at 21:35
I thought you said you wanted the to label the side lengths so the labels should be the actual lengths? That is what I understood it as, It seems you just wanted any labels, but your example shows the lengths on the edges. – Nasser Jul 12 '14 at 23:05

You can use:

HighlightMesh[DiscretizeGraphics[SSSTriangle[3, 4, 5]],
Labeled[1, "Index"]]


Or,

HighlightMesh[
DiscretizeGraphics[SSSTriangle[3, 4, 5]], {Labeled[{1, 1}, 5],
Labeled[{1, 2}, 3], Labeled[{1, 3}, 4]}]


to get:

-
 coords=Sequence@@(SSSTriangle[3,4,5]);
i=1;
Graphics[{Yellow, EdgeForm[Black], SSSTriangle[3,4,5], Black,
(Inset[Panel[Style[i++,16]],#]&/@Mean/@Transpose[{coords,RotateRight@coords}])}]


or

CycleGraph[3, VertexCoordinates -> SSSTriangle[3,4,5][[1]],
EdgeLabels->{1<->2 ->Panel[1],1<->3 ->Panel[2],2<->3 ->Panel[3]}]


-
Can you join me in chat? – Szabolcs Jul 12 '14 at 21:58
Hi @Szabolcs, just saw your chat invite.. – kglr Jul 12 '14 at 22:01

Kguler solution is much nicer, but here is my attempt. I solve the equation of lines to find the coordinate needed, then superimpose SSSTriangle with Graph using EdgeLabels where the length is put as the Label. Can be made shorter and more functional. The manual part of mapping edges to labels below can be automated more if needed.

len = {3, 4, 5};
g = SSSTriangle[3, 4, 5];
{x0, y0} = N@RegionCentroid[g]
{{x1, x2}, {y1, y2}} = N@RegionBounds[g]
xTop = x /. First@Solve[(x0 - (x2 - x1)/2)/(y0 - y1) == (x - x0)/(y2 - y0), x];
points = {{x1, y1}, {x2, y1}, {xTop, y2}}
g1 = Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1}, VertexCoordinates -> points,
EdgeLabels -> {1 <-> 2 -> len[[3]], 2 <-> 3 -> len[[1]], 3 <-> 1 -> len[[2]]},
EdgeLabelStyle -> Large];
Show[Graphics[{FaceForm[White], EdgeForm[Black], g, AspectRatio -> 1}], g1]


And if you want the centroid lines, they come for free after all the above work:

en = {3, 4, 5};
g = SSSTriangle[3, 4, 5];
{x0, y0} = N@RegionCentroid[g]
{{x1, x2}, {y1, y2}} = N@RegionBounds[g]
xTop = x /. First@Solve[(x0 - (x2 - x1)/2)/(y0 - y1) == (x - x0)/(y2 - y0), x];
points = {{x1, y1}, {x2, y1}, {xTop, y2}}
g1 = Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1}, VertexCoordinates -> points,
EdgeLabels -> {1 <-> 2 -> len[[3]], 2 <-> 3 -> len[[1]], 3 <-> 1 -> len[[2]]},
EdgeLabelStyle -> Large];
Show[Graphics[{
{FaceForm[White], EdgeForm[Black], g}, Line[{{x1, y1}, {x0, y0}}],
Line[{{x0, y0}, {x2, y1}}],
Line[{{x0, y0}, {xTop, y2}}]}],
g1]


Another option instead of using Graph is to use BoundaryMeshRegion to add the labels (there might be a way to use MesgRegion directly on SSSTriangle but can't get it to work)

len = {3, 4, 5};
g = SSSTriangle[3, 4, 5];
{x0, y0} = N@RegionCentroid[g]
{{x1, x2}, {y1, y2}} = N@RegionBounds[g]
xTop = x /. First@Solve[(x0 - (x2 - x1)/2)/(y0 - y1) == (x - x0)/(y2 - y0), x];
points = {{x1, y1}, {x2, y1}, {xTop, y2}}
g1 = BoundaryMeshRegion[points, Line[{1, 2, 3, 1}],
MeshCellLabel -> {{{1, 1}} -> len[[3]], {{1, 2}} -> len[[1]],{{1, 3}}->len[[2]]}];
Show[Graphics[{FaceForm[White], EdgeForm[Black], g}], g1]

-

Here is my late attempt based off my answer here.

tri = DiscretizeGraphics @ SSSTriangle[3, 4, 5];


Using PropertyValue we can set the labels to be part of the triangle:

PropertyValue[{tri, {1, All}}, MeshCellLabel] =
Style[Framed[#], Bold, Red, 10, Background -> Yellow] & /@ {5, 3, 4};


Visualize:

tri


-
+1).Very nice answer.Just confusing how do you know the property of MeshCellLabel.When I use PropertyList try to get it,I get a \$Failed or a blank output like this. – yode Apr 17 at 9:08