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.

One nice way to view the new and exciting Mesh objects introduced in Version 10 is by utilizing the function HighlightMesh, so I've been using it heavily. Problem is, when trying to visualize 2D convex hull regions (3D case works fine) created using ConvexHullMesh, HighlightMesh essentially ignores the Options for styling the face of the 2D polygon region. Here is an example:

SeedRandom[0];
pts = RandomReal[4, {200, 2}];
chull = ConvexHullMesh[pts]

Mathematica graphics

Now let's Style it using HighlightMesh

HighlightMesh[chull, {Style[0, Directive[PointSize[0.02], Red]], 
  Style[1, Thin, Green], Style[2, Directive[Yellow]]}]

Mathematica graphics

Notice the Yellow Color under Style[2, ..], that's for the Polygon face. This is obviously ignored for the Default color used above. Can anyone reproduce this on Windows 8.1 and other operating systems and is there an easy workaround for this?

share|improve this question
    
There are no 2-dimensional mesh elements in chull, only lines and points (examine chull // InputForm). I had the same problem here. I did not explain the difficulty, but I did come up with a workaround. –  Michael E2 Jul 30 at 20:00
    
@MichaelE2 So why does MeshCells[chull, 2] give an output - a Polygon? –  RunnyKine Jul 30 at 20:02
    
I don't know. I'm not sure at this point I'm able to give an authoritative answer to any "why" about mesh objects. It looks like an inconsistency to me. –  Michael E2 Jul 30 at 20:04
    
@MichaelE2, I saw your answer but you didn't use HighlightMesh to Style it, which is designed specifically to do this. I think it's an omission. And I agree, the Mesh objects weren't fully fleshed out. –  RunnyKine Jul 30 at 20:07
    
I didn't use it because it didn't work. Also MeshCell[..., 2] does not seem to work on it either. –  Michael E2 Jul 30 at 20:09

2 Answers 2

up vote 7 down vote accepted

An alternative workaround is to convert the BoundaryMeshRegion into a MeshRegion from the MeshCoordinates and MeshCells. This lets you use HighlightMesh as desired:

SeedRandom[0];
pts = RandomReal[4, {200, 2}];
chull = ConvexHullMesh[pts];
styles = MapThread[Style, {{0, 1, 2}, {Red, Green, Yellow}}];

fullmesh[bm_] := MeshRegion[MeshCoordinates[bm], MeshCells[bm, All]]

HighlightMesh[chull, styles]
HighlightMesh[fullmesh @ chull, styles]

enter image description here enter image description here

Note that this won't work for higher dimensional regions:

MeshCells[ConvexHullMesh[RandomReal[1, {4, 3}]], 3]

MeshCells::cnorep: There is no simple cell representation for the specified cells of the BoundaryMeshRegion in dimension 3.

share|improve this answer
    
Nice workaround. Thanks. –  RunnyKine Jul 31 at 15:12

Here is a workaround that's easy enough since it makes use of the already created Mesh region:

Graphics[GraphicsComplex[
  MeshCoordinates[chull], {Green, MeshCells[chull, 1], Red, 
   PointSize[0.02], MeshCells[chull, 0], Opacity[0.6], Yellow, 
   MeshCells[chull, 2]}]]

Mathematica graphics

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.