11
$\begingroup$

Bug introduced in 10.0 and fixed in 10.2


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?

$\endgroup$
8
  • $\begingroup$ 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. $\endgroup$
    – Michael E2
    Jul 30, 2014 at 20:00
  • $\begingroup$ @MichaelE2 So why does MeshCells[chull, 2] give an output - a Polygon? $\endgroup$
    – RunnyKine
    Jul 30, 2014 at 20:02
  • $\begingroup$ 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. $\endgroup$
    – Michael E2
    Jul 30, 2014 at 20:04
  • $\begingroup$ @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. $\endgroup$
    – RunnyKine
    Jul 30, 2014 at 20:07
  • $\begingroup$ I didn't use it because it didn't work. Also MeshCell[..., 2] does not seem to work on it either. $\endgroup$
    – Michael E2
    Jul 30, 2014 at 20:09

2 Answers 2

11
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ Nice workaround. Thanks. $\endgroup$
    – RunnyKine
    Jul 31, 2014 at 15:12
11
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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