Polygons crash kernel?Input[] inside DynamicModule causing a kernel crashGetting kernel crash from matrix operationsKernel crash when evaluating NDSolveValueCutting polygonsNIntegrate InterpolatingFunction Kernel CrashDistanceMatrix on GeoPositions causes kernel crashKernel crash with RandomIntegerFindShortestTour causes kernel crashKernel crash when calling BlockKernel crash when simplifying piecewise function

Why is the Vasa Museum in Stockholm so Popular?

Why does the friction act on the inward direction when a car makes a turn on a level road?

Why did the United States not resort to nuclear weapons in Vietnam?

How to design an effective polearm-bow hybrid?

Does a bard know when a character uses their Bardic Inspiration?

Is an "are" omitted in this sentence

Astable 555 circuit not oscillating

How does Rust's 128-bit integer `i128` work on a 64-bit system?

Why adjustbox needs a tweak of raise=-0.3ex with enumitem?

How long should I wait to plug in my refrigerator after unplugging it?

Is there a general term for the items in a directory?

Have you been refused entry into the Federal Republic of Germany?

Can't understand an ACT practice problem: Triangle appears to be isosceles, why isn't the answer 7.3~ here?

Phase portrait of a system of differential equations

How to handle many times series?

Any information about the photo with Army Uniforms

How to win an all out war against ants

A wiild aanimal, a cardinal direction, or a place by the water

A verb for when some rights are not violated?

Why have both: BJT and FET transistors on IC output?

Representation of the concatenation at the type level

Does the problem of P vs NP come under the category of Operational Research?

Different answers of calculations in LuaLaTeX on local computer, lua compiler and on overleaf

What is the reason behind water not falling from a bucket at the top of loop?



Polygons crash kernel?


Input[] inside DynamicModule causing a kernel crashGetting kernel crash from matrix operationsKernel crash when evaluating NDSolveValueCutting polygonsNIntegrate InterpolatingFunction Kernel CrashDistanceMatrix on GeoPositions causes kernel crashKernel crash with RandomIntegerFindShortestTour causes kernel crashKernel crash when calling BlockKernel crash when simplifying piecewise function






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3












$begingroup$


Having some problems Generating random Polygons and then filtering by Area, specifically filter out degenerated polygons with undefined Area is crashing the kernel in 12.0.



randomThirdPoints[n_] := Table[1/3 RandomChoice[0,1,2,3],RandomChoice[0,1,2,3],n] 


Here are some random 4-gons in the unit square:



randomPolygons4 := Table[Polygon[randomThirdPoints[4]], 100]; 


This step is consistently crashing kernel:



randomPolygons4 // Map[Area]


similarly if using Select, AssociationMap and also using RegionQ instead of Area.



Are there some safer options? Ref Page doesn't seem to help.










share|improve this question











$endgroup$













  • $begingroup$
    It's not the mapping that's the problem, it's just that the Area function crashes for some polygons. You SeedRandom when you experiment so that the problem appears consistently. For example, using RandomSeed[1], you'll see that randomPolygons4[[39]] // Area crashes the kernel. The polygon looks like this: Polygon[1/3, 1/3, 0, 0, 1/3, 1/3, 0, 2/3] This seems like a problem for WRI.
    $endgroup$
    – C. E.
    8 hours ago











  • $begingroup$
    C.E. Thanks for replicating. Yes I used Map to sample a cross-section. Will report to support. Any known workaround for randomly generated polygons?
    $endgroup$
    – alancalvitti
    8 hours ago










  • $begingroup$
    It would be better if you list polygons that crash the kernel and then ask "how can I find a workaround for these polygons?" It would make the question clearer and easier to answer.
    $endgroup$
    – C. E.
    7 hours ago











  • $begingroup$
    @C.E, I think you identified the issue, it seems confined to polygons with repeated points. Using safePointSets = Table[randomThirdPoints[4], 100] // Select[DuplicateFreeQ] and then safePointSets // Map[Polygon] // Map[Area] seems to work.
    $endgroup$
    – alancalvitti
    7 hours ago










  • $begingroup$
    ok, I undeleted my answer.
    $endgroup$
    – C. E.
    7 hours ago

















3












$begingroup$


Having some problems Generating random Polygons and then filtering by Area, specifically filter out degenerated polygons with undefined Area is crashing the kernel in 12.0.



randomThirdPoints[n_] := Table[1/3 RandomChoice[0,1,2,3],RandomChoice[0,1,2,3],n] 


Here are some random 4-gons in the unit square:



randomPolygons4 := Table[Polygon[randomThirdPoints[4]], 100]; 


This step is consistently crashing kernel:



randomPolygons4 // Map[Area]


similarly if using Select, AssociationMap and also using RegionQ instead of Area.



Are there some safer options? Ref Page doesn't seem to help.










share|improve this question











$endgroup$













  • $begingroup$
    It's not the mapping that's the problem, it's just that the Area function crashes for some polygons. You SeedRandom when you experiment so that the problem appears consistently. For example, using RandomSeed[1], you'll see that randomPolygons4[[39]] // Area crashes the kernel. The polygon looks like this: Polygon[1/3, 1/3, 0, 0, 1/3, 1/3, 0, 2/3] This seems like a problem for WRI.
    $endgroup$
    – C. E.
    8 hours ago











  • $begingroup$
    C.E. Thanks for replicating. Yes I used Map to sample a cross-section. Will report to support. Any known workaround for randomly generated polygons?
    $endgroup$
    – alancalvitti
    8 hours ago










  • $begingroup$
    It would be better if you list polygons that crash the kernel and then ask "how can I find a workaround for these polygons?" It would make the question clearer and easier to answer.
    $endgroup$
    – C. E.
    7 hours ago











  • $begingroup$
    @C.E, I think you identified the issue, it seems confined to polygons with repeated points. Using safePointSets = Table[randomThirdPoints[4], 100] // Select[DuplicateFreeQ] and then safePointSets // Map[Polygon] // Map[Area] seems to work.
    $endgroup$
    – alancalvitti
    7 hours ago










  • $begingroup$
    ok, I undeleted my answer.
    $endgroup$
    – C. E.
    7 hours ago













3












3








3


1



$begingroup$


Having some problems Generating random Polygons and then filtering by Area, specifically filter out degenerated polygons with undefined Area is crashing the kernel in 12.0.



randomThirdPoints[n_] := Table[1/3 RandomChoice[0,1,2,3],RandomChoice[0,1,2,3],n] 


Here are some random 4-gons in the unit square:



randomPolygons4 := Table[Polygon[randomThirdPoints[4]], 100]; 


This step is consistently crashing kernel:



randomPolygons4 // Map[Area]


similarly if using Select, AssociationMap and also using RegionQ instead of Area.



Are there some safer options? Ref Page doesn't seem to help.










share|improve this question











$endgroup$




Having some problems Generating random Polygons and then filtering by Area, specifically filter out degenerated polygons with undefined Area is crashing the kernel in 12.0.



randomThirdPoints[n_] := Table[1/3 RandomChoice[0,1,2,3],RandomChoice[0,1,2,3],n] 


Here are some random 4-gons in the unit square:



randomPolygons4 := Table[Polygon[randomThirdPoints[4]], 100]; 


This step is consistently crashing kernel:



randomPolygons4 // Map[Area]


similarly if using Select, AssociationMap and also using RegionQ instead of Area.



Are there some safer options? Ref Page doesn't seem to help.







graphics crash polygons






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 6 hours ago









Michael E2

157k13 gold badges215 silver badges510 bronze badges




157k13 gold badges215 silver badges510 bronze badges










asked 8 hours ago









alancalvittialancalvitti

8,2813 gold badges20 silver badges83 bronze badges




8,2813 gold badges20 silver badges83 bronze badges














  • $begingroup$
    It's not the mapping that's the problem, it's just that the Area function crashes for some polygons. You SeedRandom when you experiment so that the problem appears consistently. For example, using RandomSeed[1], you'll see that randomPolygons4[[39]] // Area crashes the kernel. The polygon looks like this: Polygon[1/3, 1/3, 0, 0, 1/3, 1/3, 0, 2/3] This seems like a problem for WRI.
    $endgroup$
    – C. E.
    8 hours ago











  • $begingroup$
    C.E. Thanks for replicating. Yes I used Map to sample a cross-section. Will report to support. Any known workaround for randomly generated polygons?
    $endgroup$
    – alancalvitti
    8 hours ago










  • $begingroup$
    It would be better if you list polygons that crash the kernel and then ask "how can I find a workaround for these polygons?" It would make the question clearer and easier to answer.
    $endgroup$
    – C. E.
    7 hours ago











  • $begingroup$
    @C.E, I think you identified the issue, it seems confined to polygons with repeated points. Using safePointSets = Table[randomThirdPoints[4], 100] // Select[DuplicateFreeQ] and then safePointSets // Map[Polygon] // Map[Area] seems to work.
    $endgroup$
    – alancalvitti
    7 hours ago










  • $begingroup$
    ok, I undeleted my answer.
    $endgroup$
    – C. E.
    7 hours ago
















  • $begingroup$
    It's not the mapping that's the problem, it's just that the Area function crashes for some polygons. You SeedRandom when you experiment so that the problem appears consistently. For example, using RandomSeed[1], you'll see that randomPolygons4[[39]] // Area crashes the kernel. The polygon looks like this: Polygon[1/3, 1/3, 0, 0, 1/3, 1/3, 0, 2/3] This seems like a problem for WRI.
    $endgroup$
    – C. E.
    8 hours ago











  • $begingroup$
    C.E. Thanks for replicating. Yes I used Map to sample a cross-section. Will report to support. Any known workaround for randomly generated polygons?
    $endgroup$
    – alancalvitti
    8 hours ago










  • $begingroup$
    It would be better if you list polygons that crash the kernel and then ask "how can I find a workaround for these polygons?" It would make the question clearer and easier to answer.
    $endgroup$
    – C. E.
    7 hours ago











  • $begingroup$
    @C.E, I think you identified the issue, it seems confined to polygons with repeated points. Using safePointSets = Table[randomThirdPoints[4], 100] // Select[DuplicateFreeQ] and then safePointSets // Map[Polygon] // Map[Area] seems to work.
    $endgroup$
    – alancalvitti
    7 hours ago










  • $begingroup$
    ok, I undeleted my answer.
    $endgroup$
    – C. E.
    7 hours ago















$begingroup$
It's not the mapping that's the problem, it's just that the Area function crashes for some polygons. You SeedRandom when you experiment so that the problem appears consistently. For example, using RandomSeed[1], you'll see that randomPolygons4[[39]] // Area crashes the kernel. The polygon looks like this: Polygon[1/3, 1/3, 0, 0, 1/3, 1/3, 0, 2/3] This seems like a problem for WRI.
$endgroup$
– C. E.
8 hours ago





$begingroup$
It's not the mapping that's the problem, it's just that the Area function crashes for some polygons. You SeedRandom when you experiment so that the problem appears consistently. For example, using RandomSeed[1], you'll see that randomPolygons4[[39]] // Area crashes the kernel. The polygon looks like this: Polygon[1/3, 1/3, 0, 0, 1/3, 1/3, 0, 2/3] This seems like a problem for WRI.
$endgroup$
– C. E.
8 hours ago













$begingroup$
C.E. Thanks for replicating. Yes I used Map to sample a cross-section. Will report to support. Any known workaround for randomly generated polygons?
$endgroup$
– alancalvitti
8 hours ago




$begingroup$
C.E. Thanks for replicating. Yes I used Map to sample a cross-section. Will report to support. Any known workaround for randomly generated polygons?
$endgroup$
– alancalvitti
8 hours ago












$begingroup$
It would be better if you list polygons that crash the kernel and then ask "how can I find a workaround for these polygons?" It would make the question clearer and easier to answer.
$endgroup$
– C. E.
7 hours ago





$begingroup$
It would be better if you list polygons that crash the kernel and then ask "how can I find a workaround for these polygons?" It would make the question clearer and easier to answer.
$endgroup$
– C. E.
7 hours ago













$begingroup$
@C.E, I think you identified the issue, it seems confined to polygons with repeated points. Using safePointSets = Table[randomThirdPoints[4], 100] // Select[DuplicateFreeQ] and then safePointSets // Map[Polygon] // Map[Area] seems to work.
$endgroup$
– alancalvitti
7 hours ago




$begingroup$
@C.E, I think you identified the issue, it seems confined to polygons with repeated points. Using safePointSets = Table[randomThirdPoints[4], 100] // Select[DuplicateFreeQ] and then safePointSets // Map[Polygon] // Map[Area] seems to work.
$endgroup$
– alancalvitti
7 hours ago












$begingroup$
ok, I undeleted my answer.
$endgroup$
– C. E.
7 hours ago




$begingroup$
ok, I undeleted my answer.
$endgroup$
– C. E.
7 hours ago










3 Answers
3






active

oldest

votes


















2












$begingroup$

One workaround for polygons with 4 different points:



Map[Area[DiscretizeGraphics[#]] &, randomPolygons4] 





share|improve this answer









$endgroup$














  • $begingroup$
    does this work for any n distinct points? (Because then I could filter these before calling Polygon)`
    $endgroup$
    – alancalvitti
    8 hours ago










  • $begingroup$
    @alancalvitti Probably yes, because DiscretizeGraphics creates a MeshRegion.
    $endgroup$
    – Ulrich Neumann
    8 hours ago










  • $begingroup$
    Given currently the polygon vertices are sampled from a regular grid in unit square, how much distortion in the Area - DiscretizedGraphics[Area] can I expect with, say, uniformly random points in unit square?
    $endgroup$
    – alancalvitti
    8 hours ago










  • $begingroup$
    @alancalvitti If the meshregion consists of triangles there is no distortion I think.
    $endgroup$
    – Ulrich Neumann
    8 hours ago


















2












$begingroup$

The "possible issues" section of the documentation for Polygon says that




Degenerate polygons are not valid geometric regions




A degenerate polygon is a polygon that has two or more vertices which are the same.



The polygons that crash the kernel seem to be of this type. You can avoid the kernel crashes by not evaluating Area on such polygons, for example by using



If[DuplicatesFreeQ[vertices], Area[Polygon[vertices]], Undefined]


or you can modify your definition of randomThirdPoints so that it doesn't generate duplicate vertices:



randomThirdPoints[n_] := 1/3 RandomSample[Tuples[0, 1, 2, 3, 2], n]





share|improve this answer











$endgroup$














  • $begingroup$
    I tried randomPolygons4 // Map[DuplicateFreeQ] // Apply[And] and always get True (note I edited my question to use SetDelayed in the definition of randomPolygons4)
    $endgroup$
    – alancalvitti
    8 hours ago










  • $begingroup$
    @alancalvitti Using DuplicateFreeQ on polygons won't work, you have to run it on the list of vertices.
    $endgroup$
    – C. E.
    7 hours ago



















0












$begingroup$

Based on C.E.'s work, vertex deduplication must be done at the point of generation, eg:



randomThirdPoints[n_] := Module[pts,
pts := Table[a RandomChoice[0,1,2,3],RandomChoice[0,1,2,3],n];
p=pts;
While[Not[DuplicateFreeQ[p]],p= pts]
p
]


this generated safe Polygons:



Table[randomThirdPoints[4], 100] // Map[DuplicateFreeQ] // Apply[And]



True




Area works for all of these, though Undefined still need to be filtered:



Table[Polygon@randomThirdPoints[4], 20] // Map[Area]



4/27, 16/63, 1/6, 7/45, 1/3, 1/6, 1/2, Undefined, 1/9, 1/6, 2/5,
4/27, 1/9, 1/18, 11/54, 1/6, 1/9, 2/9, 1/2, 1/6




Is there a more compact syntax? I don't think I've used a While loop in 20 years.






share|improve this answer









$endgroup$










  • 1




    $begingroup$
    You can use e.g. randomThirdPoints[n_] := 1/3 RandomSample[Tuples[0, 1, 2, 3, 2], n] I think, but haven't thought about it too long.
    $endgroup$
    – C. E.
    7 hours ago














Your Answer








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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
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%2f203266%2fpolygons-crash-kernel%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









2












$begingroup$

One workaround for polygons with 4 different points:



Map[Area[DiscretizeGraphics[#]] &, randomPolygons4] 





share|improve this answer









$endgroup$














  • $begingroup$
    does this work for any n distinct points? (Because then I could filter these before calling Polygon)`
    $endgroup$
    – alancalvitti
    8 hours ago










  • $begingroup$
    @alancalvitti Probably yes, because DiscretizeGraphics creates a MeshRegion.
    $endgroup$
    – Ulrich Neumann
    8 hours ago










  • $begingroup$
    Given currently the polygon vertices are sampled from a regular grid in unit square, how much distortion in the Area - DiscretizedGraphics[Area] can I expect with, say, uniformly random points in unit square?
    $endgroup$
    – alancalvitti
    8 hours ago










  • $begingroup$
    @alancalvitti If the meshregion consists of triangles there is no distortion I think.
    $endgroup$
    – Ulrich Neumann
    8 hours ago















2












$begingroup$

One workaround for polygons with 4 different points:



Map[Area[DiscretizeGraphics[#]] &, randomPolygons4] 





share|improve this answer









$endgroup$














  • $begingroup$
    does this work for any n distinct points? (Because then I could filter these before calling Polygon)`
    $endgroup$
    – alancalvitti
    8 hours ago










  • $begingroup$
    @alancalvitti Probably yes, because DiscretizeGraphics creates a MeshRegion.
    $endgroup$
    – Ulrich Neumann
    8 hours ago










  • $begingroup$
    Given currently the polygon vertices are sampled from a regular grid in unit square, how much distortion in the Area - DiscretizedGraphics[Area] can I expect with, say, uniformly random points in unit square?
    $endgroup$
    – alancalvitti
    8 hours ago










  • $begingroup$
    @alancalvitti If the meshregion consists of triangles there is no distortion I think.
    $endgroup$
    – Ulrich Neumann
    8 hours ago













2












2








2





$begingroup$

One workaround for polygons with 4 different points:



Map[Area[DiscretizeGraphics[#]] &, randomPolygons4] 





share|improve this answer









$endgroup$



One workaround for polygons with 4 different points:



Map[Area[DiscretizeGraphics[#]] &, randomPolygons4] 






share|improve this answer












share|improve this answer



share|improve this answer










answered 8 hours ago









Ulrich NeumannUlrich Neumann

13k7 silver badges20 bronze badges




13k7 silver badges20 bronze badges














  • $begingroup$
    does this work for any n distinct points? (Because then I could filter these before calling Polygon)`
    $endgroup$
    – alancalvitti
    8 hours ago










  • $begingroup$
    @alancalvitti Probably yes, because DiscretizeGraphics creates a MeshRegion.
    $endgroup$
    – Ulrich Neumann
    8 hours ago










  • $begingroup$
    Given currently the polygon vertices are sampled from a regular grid in unit square, how much distortion in the Area - DiscretizedGraphics[Area] can I expect with, say, uniformly random points in unit square?
    $endgroup$
    – alancalvitti
    8 hours ago










  • $begingroup$
    @alancalvitti If the meshregion consists of triangles there is no distortion I think.
    $endgroup$
    – Ulrich Neumann
    8 hours ago
















  • $begingroup$
    does this work for any n distinct points? (Because then I could filter these before calling Polygon)`
    $endgroup$
    – alancalvitti
    8 hours ago










  • $begingroup$
    @alancalvitti Probably yes, because DiscretizeGraphics creates a MeshRegion.
    $endgroup$
    – Ulrich Neumann
    8 hours ago










  • $begingroup$
    Given currently the polygon vertices are sampled from a regular grid in unit square, how much distortion in the Area - DiscretizedGraphics[Area] can I expect with, say, uniformly random points in unit square?
    $endgroup$
    – alancalvitti
    8 hours ago










  • $begingroup$
    @alancalvitti If the meshregion consists of triangles there is no distortion I think.
    $endgroup$
    – Ulrich Neumann
    8 hours ago















$begingroup$
does this work for any n distinct points? (Because then I could filter these before calling Polygon)`
$endgroup$
– alancalvitti
8 hours ago




$begingroup$
does this work for any n distinct points? (Because then I could filter these before calling Polygon)`
$endgroup$
– alancalvitti
8 hours ago












$begingroup$
@alancalvitti Probably yes, because DiscretizeGraphics creates a MeshRegion.
$endgroup$
– Ulrich Neumann
8 hours ago




$begingroup$
@alancalvitti Probably yes, because DiscretizeGraphics creates a MeshRegion.
$endgroup$
– Ulrich Neumann
8 hours ago












$begingroup$
Given currently the polygon vertices are sampled from a regular grid in unit square, how much distortion in the Area - DiscretizedGraphics[Area] can I expect with, say, uniformly random points in unit square?
$endgroup$
– alancalvitti
8 hours ago




$begingroup$
Given currently the polygon vertices are sampled from a regular grid in unit square, how much distortion in the Area - DiscretizedGraphics[Area] can I expect with, say, uniformly random points in unit square?
$endgroup$
– alancalvitti
8 hours ago












$begingroup$
@alancalvitti If the meshregion consists of triangles there is no distortion I think.
$endgroup$
– Ulrich Neumann
8 hours ago




$begingroup$
@alancalvitti If the meshregion consists of triangles there is no distortion I think.
$endgroup$
– Ulrich Neumann
8 hours ago













2












$begingroup$

The "possible issues" section of the documentation for Polygon says that




Degenerate polygons are not valid geometric regions




A degenerate polygon is a polygon that has two or more vertices which are the same.



The polygons that crash the kernel seem to be of this type. You can avoid the kernel crashes by not evaluating Area on such polygons, for example by using



If[DuplicatesFreeQ[vertices], Area[Polygon[vertices]], Undefined]


or you can modify your definition of randomThirdPoints so that it doesn't generate duplicate vertices:



randomThirdPoints[n_] := 1/3 RandomSample[Tuples[0, 1, 2, 3, 2], n]





share|improve this answer











$endgroup$














  • $begingroup$
    I tried randomPolygons4 // Map[DuplicateFreeQ] // Apply[And] and always get True (note I edited my question to use SetDelayed in the definition of randomPolygons4)
    $endgroup$
    – alancalvitti
    8 hours ago










  • $begingroup$
    @alancalvitti Using DuplicateFreeQ on polygons won't work, you have to run it on the list of vertices.
    $endgroup$
    – C. E.
    7 hours ago
















2












$begingroup$

The "possible issues" section of the documentation for Polygon says that




Degenerate polygons are not valid geometric regions




A degenerate polygon is a polygon that has two or more vertices which are the same.



The polygons that crash the kernel seem to be of this type. You can avoid the kernel crashes by not evaluating Area on such polygons, for example by using



If[DuplicatesFreeQ[vertices], Area[Polygon[vertices]], Undefined]


or you can modify your definition of randomThirdPoints so that it doesn't generate duplicate vertices:



randomThirdPoints[n_] := 1/3 RandomSample[Tuples[0, 1, 2, 3, 2], n]





share|improve this answer











$endgroup$














  • $begingroup$
    I tried randomPolygons4 // Map[DuplicateFreeQ] // Apply[And] and always get True (note I edited my question to use SetDelayed in the definition of randomPolygons4)
    $endgroup$
    – alancalvitti
    8 hours ago










  • $begingroup$
    @alancalvitti Using DuplicateFreeQ on polygons won't work, you have to run it on the list of vertices.
    $endgroup$
    – C. E.
    7 hours ago














2












2








2





$begingroup$

The "possible issues" section of the documentation for Polygon says that




Degenerate polygons are not valid geometric regions




A degenerate polygon is a polygon that has two or more vertices which are the same.



The polygons that crash the kernel seem to be of this type. You can avoid the kernel crashes by not evaluating Area on such polygons, for example by using



If[DuplicatesFreeQ[vertices], Area[Polygon[vertices]], Undefined]


or you can modify your definition of randomThirdPoints so that it doesn't generate duplicate vertices:



randomThirdPoints[n_] := 1/3 RandomSample[Tuples[0, 1, 2, 3, 2], n]





share|improve this answer











$endgroup$



The "possible issues" section of the documentation for Polygon says that




Degenerate polygons are not valid geometric regions




A degenerate polygon is a polygon that has two or more vertices which are the same.



The polygons that crash the kernel seem to be of this type. You can avoid the kernel crashes by not evaluating Area on such polygons, for example by using



If[DuplicatesFreeQ[vertices], Area[Polygon[vertices]], Undefined]


or you can modify your definition of randomThirdPoints so that it doesn't generate duplicate vertices:



randomThirdPoints[n_] := 1/3 RandomSample[Tuples[0, 1, 2, 3, 2], n]






share|improve this answer














share|improve this answer



share|improve this answer








edited 7 hours ago

























answered 8 hours ago









C. E.C. E.

53.6k3 gold badges102 silver badges211 bronze badges




53.6k3 gold badges102 silver badges211 bronze badges














  • $begingroup$
    I tried randomPolygons4 // Map[DuplicateFreeQ] // Apply[And] and always get True (note I edited my question to use SetDelayed in the definition of randomPolygons4)
    $endgroup$
    – alancalvitti
    8 hours ago










  • $begingroup$
    @alancalvitti Using DuplicateFreeQ on polygons won't work, you have to run it on the list of vertices.
    $endgroup$
    – C. E.
    7 hours ago

















  • $begingroup$
    I tried randomPolygons4 // Map[DuplicateFreeQ] // Apply[And] and always get True (note I edited my question to use SetDelayed in the definition of randomPolygons4)
    $endgroup$
    – alancalvitti
    8 hours ago










  • $begingroup$
    @alancalvitti Using DuplicateFreeQ on polygons won't work, you have to run it on the list of vertices.
    $endgroup$
    – C. E.
    7 hours ago
















$begingroup$
I tried randomPolygons4 // Map[DuplicateFreeQ] // Apply[And] and always get True (note I edited my question to use SetDelayed in the definition of randomPolygons4)
$endgroup$
– alancalvitti
8 hours ago




$begingroup$
I tried randomPolygons4 // Map[DuplicateFreeQ] // Apply[And] and always get True (note I edited my question to use SetDelayed in the definition of randomPolygons4)
$endgroup$
– alancalvitti
8 hours ago












$begingroup$
@alancalvitti Using DuplicateFreeQ on polygons won't work, you have to run it on the list of vertices.
$endgroup$
– C. E.
7 hours ago





$begingroup$
@alancalvitti Using DuplicateFreeQ on polygons won't work, you have to run it on the list of vertices.
$endgroup$
– C. E.
7 hours ago












0












$begingroup$

Based on C.E.'s work, vertex deduplication must be done at the point of generation, eg:



randomThirdPoints[n_] := Module[pts,
pts := Table[a RandomChoice[0,1,2,3],RandomChoice[0,1,2,3],n];
p=pts;
While[Not[DuplicateFreeQ[p]],p= pts]
p
]


this generated safe Polygons:



Table[randomThirdPoints[4], 100] // Map[DuplicateFreeQ] // Apply[And]



True




Area works for all of these, though Undefined still need to be filtered:



Table[Polygon@randomThirdPoints[4], 20] // Map[Area]



4/27, 16/63, 1/6, 7/45, 1/3, 1/6, 1/2, Undefined, 1/9, 1/6, 2/5,
4/27, 1/9, 1/18, 11/54, 1/6, 1/9, 2/9, 1/2, 1/6




Is there a more compact syntax? I don't think I've used a While loop in 20 years.






share|improve this answer









$endgroup$










  • 1




    $begingroup$
    You can use e.g. randomThirdPoints[n_] := 1/3 RandomSample[Tuples[0, 1, 2, 3, 2], n] I think, but haven't thought about it too long.
    $endgroup$
    – C. E.
    7 hours ago
















0












$begingroup$

Based on C.E.'s work, vertex deduplication must be done at the point of generation, eg:



randomThirdPoints[n_] := Module[pts,
pts := Table[a RandomChoice[0,1,2,3],RandomChoice[0,1,2,3],n];
p=pts;
While[Not[DuplicateFreeQ[p]],p= pts]
p
]


this generated safe Polygons:



Table[randomThirdPoints[4], 100] // Map[DuplicateFreeQ] // Apply[And]



True




Area works for all of these, though Undefined still need to be filtered:



Table[Polygon@randomThirdPoints[4], 20] // Map[Area]



4/27, 16/63, 1/6, 7/45, 1/3, 1/6, 1/2, Undefined, 1/9, 1/6, 2/5,
4/27, 1/9, 1/18, 11/54, 1/6, 1/9, 2/9, 1/2, 1/6




Is there a more compact syntax? I don't think I've used a While loop in 20 years.






share|improve this answer









$endgroup$










  • 1




    $begingroup$
    You can use e.g. randomThirdPoints[n_] := 1/3 RandomSample[Tuples[0, 1, 2, 3, 2], n] I think, but haven't thought about it too long.
    $endgroup$
    – C. E.
    7 hours ago














0












0








0





$begingroup$

Based on C.E.'s work, vertex deduplication must be done at the point of generation, eg:



randomThirdPoints[n_] := Module[pts,
pts := Table[a RandomChoice[0,1,2,3],RandomChoice[0,1,2,3],n];
p=pts;
While[Not[DuplicateFreeQ[p]],p= pts]
p
]


this generated safe Polygons:



Table[randomThirdPoints[4], 100] // Map[DuplicateFreeQ] // Apply[And]



True




Area works for all of these, though Undefined still need to be filtered:



Table[Polygon@randomThirdPoints[4], 20] // Map[Area]



4/27, 16/63, 1/6, 7/45, 1/3, 1/6, 1/2, Undefined, 1/9, 1/6, 2/5,
4/27, 1/9, 1/18, 11/54, 1/6, 1/9, 2/9, 1/2, 1/6




Is there a more compact syntax? I don't think I've used a While loop in 20 years.






share|improve this answer









$endgroup$



Based on C.E.'s work, vertex deduplication must be done at the point of generation, eg:



randomThirdPoints[n_] := Module[pts,
pts := Table[a RandomChoice[0,1,2,3],RandomChoice[0,1,2,3],n];
p=pts;
While[Not[DuplicateFreeQ[p]],p= pts]
p
]


this generated safe Polygons:



Table[randomThirdPoints[4], 100] // Map[DuplicateFreeQ] // Apply[And]



True




Area works for all of these, though Undefined still need to be filtered:



Table[Polygon@randomThirdPoints[4], 20] // Map[Area]



4/27, 16/63, 1/6, 7/45, 1/3, 1/6, 1/2, Undefined, 1/9, 1/6, 2/5,
4/27, 1/9, 1/18, 11/54, 1/6, 1/9, 2/9, 1/2, 1/6




Is there a more compact syntax? I don't think I've used a While loop in 20 years.







share|improve this answer












share|improve this answer



share|improve this answer










answered 7 hours ago









alancalvittialancalvitti

8,2813 gold badges20 silver badges83 bronze badges




8,2813 gold badges20 silver badges83 bronze badges










  • 1




    $begingroup$
    You can use e.g. randomThirdPoints[n_] := 1/3 RandomSample[Tuples[0, 1, 2, 3, 2], n] I think, but haven't thought about it too long.
    $endgroup$
    – C. E.
    7 hours ago













  • 1




    $begingroup$
    You can use e.g. randomThirdPoints[n_] := 1/3 RandomSample[Tuples[0, 1, 2, 3, 2], n] I think, but haven't thought about it too long.
    $endgroup$
    – C. E.
    7 hours ago








1




1




$begingroup$
You can use e.g. randomThirdPoints[n_] := 1/3 RandomSample[Tuples[0, 1, 2, 3, 2], n] I think, but haven't thought about it too long.
$endgroup$
– C. E.
7 hours ago





$begingroup$
You can use e.g. randomThirdPoints[n_] := 1/3 RandomSample[Tuples[0, 1, 2, 3, 2], n] I think, but haven't thought about it too long.
$endgroup$
– C. E.
7 hours ago


















draft saved

draft discarded
















































Thanks for contributing an answer to Mathematica Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f203266%2fpolygons-crash-kernel%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

ParseJSON using SSJSUsing AMPscript with SSJS ActivitiesHow to resubscribe a user in Marketing cloud using SSJS?Pulling Subscriber Status from Lists using SSJSRetrieving Emails using SSJSProblem in updating DE using SSJSUsing SSJS to send single email in Marketing CloudError adding EmailSendDefinition using SSJS

Кампала Садржај Географија Географија Историја Становништво Привреда Партнерски градови Референце Спољашње везе Мени за навигацију0°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.340°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.34МедијиПодациЗванични веб-сајту

Кастелфранко ди Сопра Становништво Референце Спољашње везе Мени за навигацију43°37′18″ СГШ; 11°33′32″ ИГД / 43.62156° СГШ; 11.55885° ИГД / 43.62156; 11.5588543°37′18″ СГШ; 11°33′32″ ИГД / 43.62156° СГШ; 11.55885° ИГД / 43.62156; 11.558853179688„The GeoNames geographical database”„Istituto Nazionale di Statistica”проширитиууWorldCat156923403n850174324558639-1cb14643287r(подаци)