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

Subtle ways to render a planet uninhabitable

Astable 555 circuit not oscillating

Is the first page of Novel really that important?

In MTG, was there ever a five-color deck that worked well?

Does WSL2 runs Linux in a virtual machine or alongside windows Kernel?

Is it moral to remove/hide certain parts of a photo, as a photographer?

Using Forstner bits instead of hole saws

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

What does "autolyco-sentimental" mean?

How can I perform a deterministic physics simulation?

Is law enforcement responsible for damages made by a search warrant?

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

Lower bound for the number of lattice points on high dimensional spheres

Export economy of Mars

How do I safety check that there is no light in Darkroom / Darkbag?

Do moonless nights cause dim light to become darkness, and bright light (e.g. from torches) to become dim light?

Any information about the photo with Army Uniforms

What does Argus Filch specifically do?

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

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

HackerRank Implement Queue using two stacks Solution

Being told my "network" isn't PCI compliant. I don't even have a server! Do I have to comply?

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

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



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.
    8 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.
    8 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 9 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.
    8 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.
    8 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.
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.
8 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

Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單