1

Completing questions on how to plot a ConvexHull or a DelaunayTriangulation using Graphics in Mathematica,

I would now like to plot the VoronoiDiagram within Graphics.

Considering :

Needs["ComputationalGeometry`"]
pts = RandomReal[{0, 10}, {60, 2}];
vdpts=VoronoiDiagram[pts]
Community
  • 1
  • 1
500
  • 6,509
  • 8
  • 46
  • 80

1 Answers1

3

How about

Needs["ComputationalGeometry`"]
pts = RandomReal[{0, 10}, {10, 2}]
DiagramPlot[pts]

enter image description here

or am I missing your point?

acl
  • 6,490
  • 1
  • 27
  • 33
  • @acl, Thank You ! Coming from the restrictions of plotting the CH of DT within graphics I did not think about that, thank You ! – 500 Jun 25 '11 at 12:58
  • @acl, actually, trying to implement it in my broader"Manipulated Graphicsit does not work with the following error message : Graphics is not a Graphics primitive nor directive :( : Needs["ComputationalGeometry`"] pts = RandomReal[{0, 10}, {10, 2}] Graphics[{Gray, EdgeForm[Thin], Rectangle[{0, 0}, {5, 5}], DiagramPlot[pts]}] – 500 Jun 25 '11 at 14:25
  • @500 because you are doing Graphics[{stuff, Graphics[]}] whereas you should have Show[Graphics,Graphics]. Like this: Needs["ComputationalGeometry`"] ; pts = RandomReal[{0, 10}, {10, 2}] ; Show[ Graphics[{Gray, EdgeForm[Thin], Rectangle[{0, 0}, {5, 5}]}], DiagramPlot[pts]] – acl Jun 25 '11 at 14:29
  • @acl, Ok I think I understand, the context in which I aim at using it is a bit special. I uploaded the notebook here as I think it is the best way to explain the nature of the problem. Would you have a little time to check, please let me know if you still think DiagramPlot is the appropriate solution. Many thanks for your attention, http://www.laeh500.com/LAEH/Voronoi.html – 500 Jun 25 '11 at 15:06
  • @500 Well, I manipulated the controls until I got the error, then I copied the graphic (inside the manipulate, ie not the whole manipulate object), pasted it and added //FullForm at the end. It indeed had: `Graphics[lots of stuff,Graphics[],lots more stuff]`. The problem is that you have `Graphics[{.....,If[MemberQ[theSpan, "Fixations Voronoi Diagram |"], DiagramPlot[ rejectionX[t4dataLAEH10, 9, disp, firstFixationsNOtoConsider, durationLimit, 17, 18, 11, minDistance]\[LeftDoubleBracket]All, {1, 2}\[RightDoubleBracket]]],....}]`. ie, exactly what I said above. – acl Jun 25 '11 at 15:36
  • @500 so, just to be clear: `DiagramPlot` returns something with head `Graphic`. If you wrap a `Graphic` inside a `Graphic`, it's an error. To see a graphic, you `Show` it. – acl Jun 25 '11 at 15:38
  • @500 if you really do not want to reorganize your code to fix this, you can try tacking replacing the Voronoi bit by DiagramPlot[ rejectionX[t4dataLAEH10, 9, disp, firstFixationsNOtoConsider, durationLimit, 17, 18, 11, minDistance]\[LeftDoubleBracket]All, {1, 2}\[RightDoubleBracket]] /. Graphics[c___] :> c which basically removes the `Graphics` head. This may or may not do exactly what you want but, really, if you are going to write significant chunks of code (more than a few lines), you're much much better off understanding how the whole thing works. – acl Jun 25 '11 at 15:43
  • @500 and final comment: the hack I propose is just that. It extracts the innards of an expression. It's brittle, ugly, and will end up causing headaches when you revisit your code. I'd just reorganize it if I were you, which I guess will involve a bit of reading up/experimenting on graphics structures in mma and some thought, but it'll pay off. – acl Jun 25 '11 at 15:45
  • @500 There is. `DiagramPlot` returns a `Graphic`. You have `DiagramPlot` inside a `Graphic`, so you end up with a graphic in a graphic. Anyway, maybe the method you got in your other question will work. – acl Jun 25 '11 at 15:48
  • @acl, ok. Thank You. So I do need a solution in the style of the DT or CH, I am struggling to much trying to make this work :( My Appologize. – 500 Jun 25 '11 at 16:05
  • @500 no need to apologize! didn't mean to sound condescending – acl Jun 25 '11 at 16:09
  • @acl, I made it work with the desired Style, but I now understood "by myself" why I should really have an overview of what I need in Graphics to adopt the correct strategy ;) Thank you. – 500 Jun 26 '11 at 01:19
  • @500 I know, I was speaking from painful experience... Especially with mathematica, it's easy to dive in and write code which almost works, then hack away so that it works. But it all becomes an unreadable mess very quickly, and good luck understanding it later! – acl Jun 26 '11 at 11:11