How to get size of each polygon of a voronoi diagram using Shoelace formula?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite
2












The following code gets all vertices of all polygons (mesh cells) of VoronoiMesh[pts]:



SeedRandom[3]; 
pts = RandomReal[-1, 1, 25, 2];
mesh = VoronoiMesh[pts];
vertices = MeshCoordinates[mesh];
Show[mesh, Graphics[Black, Point[pts], Red, Point[vertices]]]


This outputs:



enter image description here



My question



How can I get a list of vertices for each polygon and compute the area of each polygon using the Shoelace formula?



The output should be similar to:



Output



So, by clicking on the polygon number, it should show its vertices and its size.



I found this tool-tip image in Finding the perimeter, area and number of sides of a Voronoi cell question.










share|improve this question



















  • 1




    Do you need to use the shoelace formula, or will the built in function Area suffice?
    – Chip Hurst
    Sep 8 at 19:45










  • Yes. I need to use the shoelace formula, not built-in function.
    – Eman
    Sep 8 at 20:54















up vote
5
down vote

favorite
2












The following code gets all vertices of all polygons (mesh cells) of VoronoiMesh[pts]:



SeedRandom[3]; 
pts = RandomReal[-1, 1, 25, 2];
mesh = VoronoiMesh[pts];
vertices = MeshCoordinates[mesh];
Show[mesh, Graphics[Black, Point[pts], Red, Point[vertices]]]


This outputs:



enter image description here



My question



How can I get a list of vertices for each polygon and compute the area of each polygon using the Shoelace formula?



The output should be similar to:



Output



So, by clicking on the polygon number, it should show its vertices and its size.



I found this tool-tip image in Finding the perimeter, area and number of sides of a Voronoi cell question.










share|improve this question



















  • 1




    Do you need to use the shoelace formula, or will the built in function Area suffice?
    – Chip Hurst
    Sep 8 at 19:45










  • Yes. I need to use the shoelace formula, not built-in function.
    – Eman
    Sep 8 at 20:54













up vote
5
down vote

favorite
2









up vote
5
down vote

favorite
2






2





The following code gets all vertices of all polygons (mesh cells) of VoronoiMesh[pts]:



SeedRandom[3]; 
pts = RandomReal[-1, 1, 25, 2];
mesh = VoronoiMesh[pts];
vertices = MeshCoordinates[mesh];
Show[mesh, Graphics[Black, Point[pts], Red, Point[vertices]]]


This outputs:



enter image description here



My question



How can I get a list of vertices for each polygon and compute the area of each polygon using the Shoelace formula?



The output should be similar to:



Output



So, by clicking on the polygon number, it should show its vertices and its size.



I found this tool-tip image in Finding the perimeter, area and number of sides of a Voronoi cell question.










share|improve this question















The following code gets all vertices of all polygons (mesh cells) of VoronoiMesh[pts]:



SeedRandom[3]; 
pts = RandomReal[-1, 1, 25, 2];
mesh = VoronoiMesh[pts];
vertices = MeshCoordinates[mesh];
Show[mesh, Graphics[Black, Point[pts], Red, Point[vertices]]]


This outputs:



enter image description here



My question



How can I get a list of vertices for each polygon and compute the area of each polygon using the Shoelace formula?



The output should be similar to:



Output



So, by clicking on the polygon number, it should show its vertices and its size.



I found this tool-tip image in Finding the perimeter, area and number of sides of a Voronoi cell question.







computational-geometry polygons






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 8 at 22:24









Lukas Lang

5,2181525




5,2181525










asked Sep 8 at 18:13









Eman

926




926







  • 1




    Do you need to use the shoelace formula, or will the built in function Area suffice?
    – Chip Hurst
    Sep 8 at 19:45










  • Yes. I need to use the shoelace formula, not built-in function.
    – Eman
    Sep 8 at 20:54













  • 1




    Do you need to use the shoelace formula, or will the built in function Area suffice?
    – Chip Hurst
    Sep 8 at 19:45










  • Yes. I need to use the shoelace formula, not built-in function.
    – Eman
    Sep 8 at 20:54








1




1




Do you need to use the shoelace formula, or will the built in function Area suffice?
– Chip Hurst
Sep 8 at 19:45




Do you need to use the shoelace formula, or will the built in function Area suffice?
– Chip Hurst
Sep 8 at 19:45












Yes. I need to use the shoelace formula, not built-in function.
– Eman
Sep 8 at 20:54





Yes. I need to use the shoelace formula, not built-in function.
– Eman
Sep 8 at 20:54











3 Answers
3






active

oldest

votes

















up vote
1
down vote



accepted










polygons = Join @@ MeshCells[mesh, 2, "Multicells" -> True][[All, 1]];
polygondata = With[x = MeshCoordinates[mesh], Map[
p [Function] Partition[x[[p]], 2, 1, 1],
polygons
]];
areas = 0.5 Total[Map[Det, polygondata, 2], 2];
circumferences = Total[Map[Norm, Differences /@ polygondata, 2], 2];


For the tooltipping, you can also use the option MeshCellLabel of MeshRegion, but that's are a bit unwieldy:



MeshRegion[mesh, MeshCellLabel -> Map[
i [Function] (2, i -> Tooltip[
i,
Grid[
"Vertices", polygons[[i]],
"Vertex Coordinates", polygondata[[i, All, 1]],
"Area", areas[[i]],
"Perimeter", circumferences[[i]]
,
Alignment -> Left, Top
]
]
),
Range[MeshCellCount[mesh, 2]]
]
]





share|improve this answer






















  • Thanks so much for your help and your edit. That is helpful for getting the polygons' sizes of each polygon. If I want to show the vertices values of each polygon also. How can I do that?? Any suggestions??
    – Eman
    Sep 8 at 19:20






  • 1




    Have a look at the last edit.
    – Henrik Schumacher
    Sep 8 at 19:28










  • Thanks so much for your help. I am really sorry for disturbance. But, I think the vertices in the code, gives the order of the vertices of each polygon, not the values of the vertices' points.
    – Eman
    Sep 8 at 19:37






  • 1




    Is it better now?
    – Henrik Schumacher
    Sep 8 at 19:42






  • 1




    You're welcome.
    – Henrik Schumacher
    Sep 8 at 20:57

















up vote
4
down vote













Use MeshPrimitives like this:



Show[Graphics[FaceForm@RGBColor[
0.666, 0.776, 0.952],
Table[Tooltip[p,
Grid@"Perimeter", Perimeter@p, "Area", Area@p, "Edges",
Length @@ p], p, MeshPrimitives[mesh, 2]]],
Graphics[Black, Point[pts], Red, Point[vertices]]]


enter image description here






share|improve this answer




















  • Thanks so much for your help. But, if I want the vertices of each polygon to be shown also with area,edges and Perimeter. How to do that??
    – Eman
    Sep 8 at 18:41






  • 1




    How are you ordering them?
    – M.R.
    Sep 8 at 18:47











  • Thanks so much for your help and your reply. What did you mean by them ? Did you mean the vertices?? If you mean the vertices, I don't order them. the code get all vertices of all voronoi polygons. I want to get the vertices of each polygon, separately. So, by clicking on each polygon; I can get its vertices.
    – Eman
    Sep 8 at 19:12






  • 2




    Note that PropertyValue[mesh, 2, MeshCellMeasure] is a faster way to get all of the areas. However I don't think the other properties can be computed in this way.
    – Chip Hurst
    Sep 8 at 19:52

















up vote
2
down vote













Here's an efficient way to implement the shoelace formula, assuming no self intersections:



ShoelaceArea[Polygon[pts_?MatrixQ]] := 
0.5 * #1.(RotateLeft[#2] - RotateRight[#2])& @@ Transpose[pts]


A comparison:



shoeareas = ShoelaceArea /@ MeshPrimitives[mesh, 2]; // AbsoluteTiming



 0.000233, Null



areas = PropertyValue[mesh, 2, MeshCellMeasure]; // AbsoluteTiming



 0.000013, Null



Max[Abs[shoeareas - areas]]



3.33067*10^-16






share|improve this answer




















  • Thanks so much for your help.
    – Eman
    Sep 8 at 21:12










Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181520%2fhow-to-get-size-of-each-polygon-of-a-voronoi-diagram-using-shoelace-formula%23new-answer', 'question_page');

);

Post as a guest






























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










polygons = Join @@ MeshCells[mesh, 2, "Multicells" -> True][[All, 1]];
polygondata = With[x = MeshCoordinates[mesh], Map[
p [Function] Partition[x[[p]], 2, 1, 1],
polygons
]];
areas = 0.5 Total[Map[Det, polygondata, 2], 2];
circumferences = Total[Map[Norm, Differences /@ polygondata, 2], 2];


For the tooltipping, you can also use the option MeshCellLabel of MeshRegion, but that's are a bit unwieldy:



MeshRegion[mesh, MeshCellLabel -> Map[
i [Function] (2, i -> Tooltip[
i,
Grid[
"Vertices", polygons[[i]],
"Vertex Coordinates", polygondata[[i, All, 1]],
"Area", areas[[i]],
"Perimeter", circumferences[[i]]
,
Alignment -> Left, Top
]
]
),
Range[MeshCellCount[mesh, 2]]
]
]





share|improve this answer






















  • Thanks so much for your help and your edit. That is helpful for getting the polygons' sizes of each polygon. If I want to show the vertices values of each polygon also. How can I do that?? Any suggestions??
    – Eman
    Sep 8 at 19:20






  • 1




    Have a look at the last edit.
    – Henrik Schumacher
    Sep 8 at 19:28










  • Thanks so much for your help. I am really sorry for disturbance. But, I think the vertices in the code, gives the order of the vertices of each polygon, not the values of the vertices' points.
    – Eman
    Sep 8 at 19:37






  • 1




    Is it better now?
    – Henrik Schumacher
    Sep 8 at 19:42






  • 1




    You're welcome.
    – Henrik Schumacher
    Sep 8 at 20:57














up vote
1
down vote



accepted










polygons = Join @@ MeshCells[mesh, 2, "Multicells" -> True][[All, 1]];
polygondata = With[x = MeshCoordinates[mesh], Map[
p [Function] Partition[x[[p]], 2, 1, 1],
polygons
]];
areas = 0.5 Total[Map[Det, polygondata, 2], 2];
circumferences = Total[Map[Norm, Differences /@ polygondata, 2], 2];


For the tooltipping, you can also use the option MeshCellLabel of MeshRegion, but that's are a bit unwieldy:



MeshRegion[mesh, MeshCellLabel -> Map[
i [Function] (2, i -> Tooltip[
i,
Grid[
"Vertices", polygons[[i]],
"Vertex Coordinates", polygondata[[i, All, 1]],
"Area", areas[[i]],
"Perimeter", circumferences[[i]]
,
Alignment -> Left, Top
]
]
),
Range[MeshCellCount[mesh, 2]]
]
]





share|improve this answer






















  • Thanks so much for your help and your edit. That is helpful for getting the polygons' sizes of each polygon. If I want to show the vertices values of each polygon also. How can I do that?? Any suggestions??
    – Eman
    Sep 8 at 19:20






  • 1




    Have a look at the last edit.
    – Henrik Schumacher
    Sep 8 at 19:28










  • Thanks so much for your help. I am really sorry for disturbance. But, I think the vertices in the code, gives the order of the vertices of each polygon, not the values of the vertices' points.
    – Eman
    Sep 8 at 19:37






  • 1




    Is it better now?
    – Henrik Schumacher
    Sep 8 at 19:42






  • 1




    You're welcome.
    – Henrik Schumacher
    Sep 8 at 20:57












up vote
1
down vote



accepted







up vote
1
down vote



accepted






polygons = Join @@ MeshCells[mesh, 2, "Multicells" -> True][[All, 1]];
polygondata = With[x = MeshCoordinates[mesh], Map[
p [Function] Partition[x[[p]], 2, 1, 1],
polygons
]];
areas = 0.5 Total[Map[Det, polygondata, 2], 2];
circumferences = Total[Map[Norm, Differences /@ polygondata, 2], 2];


For the tooltipping, you can also use the option MeshCellLabel of MeshRegion, but that's are a bit unwieldy:



MeshRegion[mesh, MeshCellLabel -> Map[
i [Function] (2, i -> Tooltip[
i,
Grid[
"Vertices", polygons[[i]],
"Vertex Coordinates", polygondata[[i, All, 1]],
"Area", areas[[i]],
"Perimeter", circumferences[[i]]
,
Alignment -> Left, Top
]
]
),
Range[MeshCellCount[mesh, 2]]
]
]





share|improve this answer














polygons = Join @@ MeshCells[mesh, 2, "Multicells" -> True][[All, 1]];
polygondata = With[x = MeshCoordinates[mesh], Map[
p [Function] Partition[x[[p]], 2, 1, 1],
polygons
]];
areas = 0.5 Total[Map[Det, polygondata, 2], 2];
circumferences = Total[Map[Norm, Differences /@ polygondata, 2], 2];


For the tooltipping, you can also use the option MeshCellLabel of MeshRegion, but that's are a bit unwieldy:



MeshRegion[mesh, MeshCellLabel -> Map[
i [Function] (2, i -> Tooltip[
i,
Grid[
"Vertices", polygons[[i]],
"Vertex Coordinates", polygondata[[i, All, 1]],
"Area", areas[[i]],
"Perimeter", circumferences[[i]]
,
Alignment -> Left, Top
]
]
),
Range[MeshCellCount[mesh, 2]]
]
]






share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 8 at 19:42

























answered Sep 8 at 18:25









Henrik Schumacher

37.5k249106




37.5k249106











  • Thanks so much for your help and your edit. That is helpful for getting the polygons' sizes of each polygon. If I want to show the vertices values of each polygon also. How can I do that?? Any suggestions??
    – Eman
    Sep 8 at 19:20






  • 1




    Have a look at the last edit.
    – Henrik Schumacher
    Sep 8 at 19:28










  • Thanks so much for your help. I am really sorry for disturbance. But, I think the vertices in the code, gives the order of the vertices of each polygon, not the values of the vertices' points.
    – Eman
    Sep 8 at 19:37






  • 1




    Is it better now?
    – Henrik Schumacher
    Sep 8 at 19:42






  • 1




    You're welcome.
    – Henrik Schumacher
    Sep 8 at 20:57
















  • Thanks so much for your help and your edit. That is helpful for getting the polygons' sizes of each polygon. If I want to show the vertices values of each polygon also. How can I do that?? Any suggestions??
    – Eman
    Sep 8 at 19:20






  • 1




    Have a look at the last edit.
    – Henrik Schumacher
    Sep 8 at 19:28










  • Thanks so much for your help. I am really sorry for disturbance. But, I think the vertices in the code, gives the order of the vertices of each polygon, not the values of the vertices' points.
    – Eman
    Sep 8 at 19:37






  • 1




    Is it better now?
    – Henrik Schumacher
    Sep 8 at 19:42






  • 1




    You're welcome.
    – Henrik Schumacher
    Sep 8 at 20:57















Thanks so much for your help and your edit. That is helpful for getting the polygons' sizes of each polygon. If I want to show the vertices values of each polygon also. How can I do that?? Any suggestions??
– Eman
Sep 8 at 19:20




Thanks so much for your help and your edit. That is helpful for getting the polygons' sizes of each polygon. If I want to show the vertices values of each polygon also. How can I do that?? Any suggestions??
– Eman
Sep 8 at 19:20




1




1




Have a look at the last edit.
– Henrik Schumacher
Sep 8 at 19:28




Have a look at the last edit.
– Henrik Schumacher
Sep 8 at 19:28












Thanks so much for your help. I am really sorry for disturbance. But, I think the vertices in the code, gives the order of the vertices of each polygon, not the values of the vertices' points.
– Eman
Sep 8 at 19:37




Thanks so much for your help. I am really sorry for disturbance. But, I think the vertices in the code, gives the order of the vertices of each polygon, not the values of the vertices' points.
– Eman
Sep 8 at 19:37




1




1




Is it better now?
– Henrik Schumacher
Sep 8 at 19:42




Is it better now?
– Henrik Schumacher
Sep 8 at 19:42




1




1




You're welcome.
– Henrik Schumacher
Sep 8 at 20:57




You're welcome.
– Henrik Schumacher
Sep 8 at 20:57










up vote
4
down vote













Use MeshPrimitives like this:



Show[Graphics[FaceForm@RGBColor[
0.666, 0.776, 0.952],
Table[Tooltip[p,
Grid@"Perimeter", Perimeter@p, "Area", Area@p, "Edges",
Length @@ p], p, MeshPrimitives[mesh, 2]]],
Graphics[Black, Point[pts], Red, Point[vertices]]]


enter image description here






share|improve this answer




















  • Thanks so much for your help. But, if I want the vertices of each polygon to be shown also with area,edges and Perimeter. How to do that??
    – Eman
    Sep 8 at 18:41






  • 1




    How are you ordering them?
    – M.R.
    Sep 8 at 18:47











  • Thanks so much for your help and your reply. What did you mean by them ? Did you mean the vertices?? If you mean the vertices, I don't order them. the code get all vertices of all voronoi polygons. I want to get the vertices of each polygon, separately. So, by clicking on each polygon; I can get its vertices.
    – Eman
    Sep 8 at 19:12






  • 2




    Note that PropertyValue[mesh, 2, MeshCellMeasure] is a faster way to get all of the areas. However I don't think the other properties can be computed in this way.
    – Chip Hurst
    Sep 8 at 19:52














up vote
4
down vote













Use MeshPrimitives like this:



Show[Graphics[FaceForm@RGBColor[
0.666, 0.776, 0.952],
Table[Tooltip[p,
Grid@"Perimeter", Perimeter@p, "Area", Area@p, "Edges",
Length @@ p], p, MeshPrimitives[mesh, 2]]],
Graphics[Black, Point[pts], Red, Point[vertices]]]


enter image description here






share|improve this answer




















  • Thanks so much for your help. But, if I want the vertices of each polygon to be shown also with area,edges and Perimeter. How to do that??
    – Eman
    Sep 8 at 18:41






  • 1




    How are you ordering them?
    – M.R.
    Sep 8 at 18:47











  • Thanks so much for your help and your reply. What did you mean by them ? Did you mean the vertices?? If you mean the vertices, I don't order them. the code get all vertices of all voronoi polygons. I want to get the vertices of each polygon, separately. So, by clicking on each polygon; I can get its vertices.
    – Eman
    Sep 8 at 19:12






  • 2




    Note that PropertyValue[mesh, 2, MeshCellMeasure] is a faster way to get all of the areas. However I don't think the other properties can be computed in this way.
    – Chip Hurst
    Sep 8 at 19:52












up vote
4
down vote










up vote
4
down vote









Use MeshPrimitives like this:



Show[Graphics[FaceForm@RGBColor[
0.666, 0.776, 0.952],
Table[Tooltip[p,
Grid@"Perimeter", Perimeter@p, "Area", Area@p, "Edges",
Length @@ p], p, MeshPrimitives[mesh, 2]]],
Graphics[Black, Point[pts], Red, Point[vertices]]]


enter image description here






share|improve this answer












Use MeshPrimitives like this:



Show[Graphics[FaceForm@RGBColor[
0.666, 0.776, 0.952],
Table[Tooltip[p,
Grid@"Perimeter", Perimeter@p, "Area", Area@p, "Edges",
Length @@ p], p, MeshPrimitives[mesh, 2]]],
Graphics[Black, Point[pts], Red, Point[vertices]]]


enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Sep 8 at 18:31









M.R.

15.2k551177




15.2k551177











  • Thanks so much for your help. But, if I want the vertices of each polygon to be shown also with area,edges and Perimeter. How to do that??
    – Eman
    Sep 8 at 18:41






  • 1




    How are you ordering them?
    – M.R.
    Sep 8 at 18:47











  • Thanks so much for your help and your reply. What did you mean by them ? Did you mean the vertices?? If you mean the vertices, I don't order them. the code get all vertices of all voronoi polygons. I want to get the vertices of each polygon, separately. So, by clicking on each polygon; I can get its vertices.
    – Eman
    Sep 8 at 19:12






  • 2




    Note that PropertyValue[mesh, 2, MeshCellMeasure] is a faster way to get all of the areas. However I don't think the other properties can be computed in this way.
    – Chip Hurst
    Sep 8 at 19:52
















  • Thanks so much for your help. But, if I want the vertices of each polygon to be shown also with area,edges and Perimeter. How to do that??
    – Eman
    Sep 8 at 18:41






  • 1




    How are you ordering them?
    – M.R.
    Sep 8 at 18:47











  • Thanks so much for your help and your reply. What did you mean by them ? Did you mean the vertices?? If you mean the vertices, I don't order them. the code get all vertices of all voronoi polygons. I want to get the vertices of each polygon, separately. So, by clicking on each polygon; I can get its vertices.
    – Eman
    Sep 8 at 19:12






  • 2




    Note that PropertyValue[mesh, 2, MeshCellMeasure] is a faster way to get all of the areas. However I don't think the other properties can be computed in this way.
    – Chip Hurst
    Sep 8 at 19:52















Thanks so much for your help. But, if I want the vertices of each polygon to be shown also with area,edges and Perimeter. How to do that??
– Eman
Sep 8 at 18:41




Thanks so much for your help. But, if I want the vertices of each polygon to be shown also with area,edges and Perimeter. How to do that??
– Eman
Sep 8 at 18:41




1




1




How are you ordering them?
– M.R.
Sep 8 at 18:47





How are you ordering them?
– M.R.
Sep 8 at 18:47













Thanks so much for your help and your reply. What did you mean by them ? Did you mean the vertices?? If you mean the vertices, I don't order them. the code get all vertices of all voronoi polygons. I want to get the vertices of each polygon, separately. So, by clicking on each polygon; I can get its vertices.
– Eman
Sep 8 at 19:12




Thanks so much for your help and your reply. What did you mean by them ? Did you mean the vertices?? If you mean the vertices, I don't order them. the code get all vertices of all voronoi polygons. I want to get the vertices of each polygon, separately. So, by clicking on each polygon; I can get its vertices.
– Eman
Sep 8 at 19:12




2




2




Note that PropertyValue[mesh, 2, MeshCellMeasure] is a faster way to get all of the areas. However I don't think the other properties can be computed in this way.
– Chip Hurst
Sep 8 at 19:52




Note that PropertyValue[mesh, 2, MeshCellMeasure] is a faster way to get all of the areas. However I don't think the other properties can be computed in this way.
– Chip Hurst
Sep 8 at 19:52










up vote
2
down vote













Here's an efficient way to implement the shoelace formula, assuming no self intersections:



ShoelaceArea[Polygon[pts_?MatrixQ]] := 
0.5 * #1.(RotateLeft[#2] - RotateRight[#2])& @@ Transpose[pts]


A comparison:



shoeareas = ShoelaceArea /@ MeshPrimitives[mesh, 2]; // AbsoluteTiming



 0.000233, Null



areas = PropertyValue[mesh, 2, MeshCellMeasure]; // AbsoluteTiming



 0.000013, Null



Max[Abs[shoeareas - areas]]



3.33067*10^-16






share|improve this answer




















  • Thanks so much for your help.
    – Eman
    Sep 8 at 21:12














up vote
2
down vote













Here's an efficient way to implement the shoelace formula, assuming no self intersections:



ShoelaceArea[Polygon[pts_?MatrixQ]] := 
0.5 * #1.(RotateLeft[#2] - RotateRight[#2])& @@ Transpose[pts]


A comparison:



shoeareas = ShoelaceArea /@ MeshPrimitives[mesh, 2]; // AbsoluteTiming



 0.000233, Null



areas = PropertyValue[mesh, 2, MeshCellMeasure]; // AbsoluteTiming



 0.000013, Null



Max[Abs[shoeareas - areas]]



3.33067*10^-16






share|improve this answer




















  • Thanks so much for your help.
    – Eman
    Sep 8 at 21:12












up vote
2
down vote










up vote
2
down vote









Here's an efficient way to implement the shoelace formula, assuming no self intersections:



ShoelaceArea[Polygon[pts_?MatrixQ]] := 
0.5 * #1.(RotateLeft[#2] - RotateRight[#2])& @@ Transpose[pts]


A comparison:



shoeareas = ShoelaceArea /@ MeshPrimitives[mesh, 2]; // AbsoluteTiming



 0.000233, Null



areas = PropertyValue[mesh, 2, MeshCellMeasure]; // AbsoluteTiming



 0.000013, Null



Max[Abs[shoeareas - areas]]



3.33067*10^-16






share|improve this answer












Here's an efficient way to implement the shoelace formula, assuming no self intersections:



ShoelaceArea[Polygon[pts_?MatrixQ]] := 
0.5 * #1.(RotateLeft[#2] - RotateRight[#2])& @@ Transpose[pts]


A comparison:



shoeareas = ShoelaceArea /@ MeshPrimitives[mesh, 2]; // AbsoluteTiming



 0.000233, Null



areas = PropertyValue[mesh, 2, MeshCellMeasure]; // AbsoluteTiming



 0.000013, Null



Max[Abs[shoeareas - areas]]



3.33067*10^-16







share|improve this answer












share|improve this answer



share|improve this answer










answered Sep 8 at 21:10









Chip Hurst

18.9k15484




18.9k15484











  • Thanks so much for your help.
    – Eman
    Sep 8 at 21:12
















  • Thanks so much for your help.
    – Eman
    Sep 8 at 21:12















Thanks so much for your help.
– Eman
Sep 8 at 21:12




Thanks so much for your help.
– Eman
Sep 8 at 21:12

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181520%2fhow-to-get-size-of-each-polygon-of-a-voronoi-diagram-using-shoelace-formula%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

List of Gilmore Girls characters

Confectionery