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;
$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.
graphics crash polygons
$endgroup$
|
show 3 more comments
$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.
graphics crash polygons
$endgroup$
$begingroup$
It's not the mapping that's the problem, it's just that theArea
function crashes for some polygons. YouSeedRandom
when you experiment so that the problem appears consistently. For example, usingRandomSeed[1]
, you'll see thatrandomPolygons4[[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. UsingsafePointSets = Table[randomThirdPoints[4], 100] // Select[DuplicateFreeQ]
and thensafePointSets // Map[Polygon] // Map[Area]
seems to work.
$endgroup$
– alancalvitti
7 hours ago
$begingroup$
ok, I undeleted my answer.
$endgroup$
– C. E.
7 hours ago
|
show 3 more comments
$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.
graphics crash polygons
$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
graphics crash polygons
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 theArea
function crashes for some polygons. YouSeedRandom
when you experiment so that the problem appears consistently. For example, usingRandomSeed[1]
, you'll see thatrandomPolygons4[[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. UsingsafePointSets = Table[randomThirdPoints[4], 100] // Select[DuplicateFreeQ]
and thensafePointSets // Map[Polygon] // Map[Area]
seems to work.
$endgroup$
– alancalvitti
7 hours ago
$begingroup$
ok, I undeleted my answer.
$endgroup$
– C. E.
7 hours ago
|
show 3 more comments
$begingroup$
It's not the mapping that's the problem, it's just that theArea
function crashes for some polygons. YouSeedRandom
when you experiment so that the problem appears consistently. For example, usingRandomSeed[1]
, you'll see thatrandomPolygons4[[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. UsingsafePointSets = Table[randomThirdPoints[4], 100] // Select[DuplicateFreeQ]
and thensafePointSets // 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
|
show 3 more comments
3 Answers
3
active
oldest
votes
$begingroup$
One workaround for polygons with 4 different points:
Map[Area[DiscretizeGraphics[#]] &, randomPolygons4]
$endgroup$
$begingroup$
does this work for anyn
distinct points? (Because then I could filter these before calling Polygon)`
$endgroup$
– alancalvitti
8 hours ago
$begingroup$
@alancalvitti Probably yes, becauseDiscretizeGraphics
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 theArea - 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
add a comment |
$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]
$endgroup$
$begingroup$
I triedrandomPolygons4 // Map[DuplicateFreeQ] // Apply[And]
and always getTrue
(note I edited my question to useSetDelayed
in the definition ofrandomPolygons4
)
$endgroup$
– alancalvitti
8 hours ago
$begingroup$
@alancalvitti UsingDuplicateFreeQ
on polygons won't work, you have to run it on the list of vertices.
$endgroup$
– C. E.
7 hours ago
add a comment |
$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 Polygon
s:
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.
$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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
$begingroup$
One workaround for polygons with 4 different points:
Map[Area[DiscretizeGraphics[#]] &, randomPolygons4]
$endgroup$
$begingroup$
does this work for anyn
distinct points? (Because then I could filter these before calling Polygon)`
$endgroup$
– alancalvitti
8 hours ago
$begingroup$
@alancalvitti Probably yes, becauseDiscretizeGraphics
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 theArea - 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
add a comment |
$begingroup$
One workaround for polygons with 4 different points:
Map[Area[DiscretizeGraphics[#]] &, randomPolygons4]
$endgroup$
$begingroup$
does this work for anyn
distinct points? (Because then I could filter these before calling Polygon)`
$endgroup$
– alancalvitti
8 hours ago
$begingroup$
@alancalvitti Probably yes, becauseDiscretizeGraphics
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 theArea - 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
add a comment |
$begingroup$
One workaround for polygons with 4 different points:
Map[Area[DiscretizeGraphics[#]] &, randomPolygons4]
$endgroup$
One workaround for polygons with 4 different points:
Map[Area[DiscretizeGraphics[#]] &, randomPolygons4]
answered 8 hours ago
Ulrich NeumannUlrich Neumann
13k7 silver badges20 bronze badges
13k7 silver badges20 bronze badges
$begingroup$
does this work for anyn
distinct points? (Because then I could filter these before calling Polygon)`
$endgroup$
– alancalvitti
8 hours ago
$begingroup$
@alancalvitti Probably yes, becauseDiscretizeGraphics
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 theArea - 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
add a comment |
$begingroup$
does this work for anyn
distinct points? (Because then I could filter these before calling Polygon)`
$endgroup$
– alancalvitti
8 hours ago
$begingroup$
@alancalvitti Probably yes, becauseDiscretizeGraphics
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 theArea - 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
add a comment |
$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]
$endgroup$
$begingroup$
I triedrandomPolygons4 // Map[DuplicateFreeQ] // Apply[And]
and always getTrue
(note I edited my question to useSetDelayed
in the definition ofrandomPolygons4
)
$endgroup$
– alancalvitti
8 hours ago
$begingroup$
@alancalvitti UsingDuplicateFreeQ
on polygons won't work, you have to run it on the list of vertices.
$endgroup$
– C. E.
7 hours ago
add a comment |
$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]
$endgroup$
$begingroup$
I triedrandomPolygons4 // Map[DuplicateFreeQ] // Apply[And]
and always getTrue
(note I edited my question to useSetDelayed
in the definition ofrandomPolygons4
)
$endgroup$
– alancalvitti
8 hours ago
$begingroup$
@alancalvitti UsingDuplicateFreeQ
on polygons won't work, you have to run it on the list of vertices.
$endgroup$
– C. E.
7 hours ago
add a comment |
$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]
$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]
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 triedrandomPolygons4 // Map[DuplicateFreeQ] // Apply[And]
and always getTrue
(note I edited my question to useSetDelayed
in the definition ofrandomPolygons4
)
$endgroup$
– alancalvitti
8 hours ago
$begingroup$
@alancalvitti UsingDuplicateFreeQ
on polygons won't work, you have to run it on the list of vertices.
$endgroup$
– C. E.
7 hours ago
add a comment |
$begingroup$
I triedrandomPolygons4 // Map[DuplicateFreeQ] // Apply[And]
and always getTrue
(note I edited my question to useSetDelayed
in the definition ofrandomPolygons4
)
$endgroup$
– alancalvitti
8 hours ago
$begingroup$
@alancalvitti UsingDuplicateFreeQ
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
add a comment |
$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 Polygon
s:
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.
$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
add a comment |
$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 Polygon
s:
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.
$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
add a comment |
$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 Polygon
s:
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.
$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 Polygon
s:
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
$begingroup$
It's not the mapping that's the problem, it's just that the
Area
function crashes for some polygons. YouSeedRandom
when you experiment so that the problem appears consistently. For example, usingRandomSeed[1]
, you'll see thatrandomPolygons4[[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 thensafePointSets // Map[Polygon] // Map[Area]
seems to work.$endgroup$
– alancalvitti
7 hours ago
$begingroup$
ok, I undeleted my answer.
$endgroup$
– C. E.
7 hours ago