Labeling triangle edges in Mathematica 10
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]}]
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]