Plot VoronoiDiagram using Graphics in Mathematica
Asked Answered
C

1

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]
Chitarrone answered 25/6, 2011 at 12:36 Comment(0)
A
3

How about

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

enter image description here

or am I missing your point?

Arriaga answered 25/6, 2011 at 12:49 Comment(13)
@acl, Thank You ! Coming from the restrictions of plotting the CH of DT within graphics I did not think about that, thank You !Chitarrone
@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]}]Chitarrone
@Chitarrone 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]]Arriaga
@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, laeh500.com/LAEH/Voronoi.htmlChitarrone
@Chitarrone 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.Arriaga
@Chitarrone 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.Arriaga
@Chitarrone 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.Arriaga
@Chitarrone 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.Arriaga
@Chitarrone 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.Arriaga
@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.Chitarrone
@Chitarrone no need to apologize! didn't mean to sound condescendingArriaga
@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.Chitarrone
@Chitarrone 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!Arriaga

© 2022 - 2024 — McMap. All rights reserved.