Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

enter image description here

share|improve this question
    
If we can figure out how to convert this to a MeshRegion, then this is possible with HighlightMesh. –  Szabolcs Jul 12 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 at 23:05

3 Answers 3

up vote 8 down vote accepted

You can use:

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

enter image description here

Or,

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

to get:

enter image description here

share|improve this answer
 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}])}]

enter image description here

or

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

enter image description here

share|improve this answer
    
Can you join me in chat? –  Szabolcs Jul 12 at 21:58
    
Hi @Szabolcs, just saw your chat invite.. –  kguler Jul 12 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.

Mathematica graphics

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:

Mathematica graphics

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)

Mathematica graphics

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]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.