how to generate random convex quadrilaterals using circles (actually inscribed within circles)?
I would like to generate random convex quadrilaterals using circles, my tutor has suggested to using randomreal to generate 4 numbers and scale the sum of them to 2pi, and then use trigonometry properties to do that, I do not see how that works, can somebody gives some hints about how I should go with it then I can try it out.
graphics parametricplot
add a comment |
I would like to generate random convex quadrilaterals using circles, my tutor has suggested to using randomreal to generate 4 numbers and scale the sum of them to 2pi, and then use trigonometry properties to do that, I do not see how that works, can somebody gives some hints about how I should go with it then I can try it out.
graphics parametricplot
3
"Use trigonometry" means place them on the unit circle. Then connect the dots.
– Daniel Lichtblau
Dec 16 at 15:18
add a comment |
I would like to generate random convex quadrilaterals using circles, my tutor has suggested to using randomreal to generate 4 numbers and scale the sum of them to 2pi, and then use trigonometry properties to do that, I do not see how that works, can somebody gives some hints about how I should go with it then I can try it out.
graphics parametricplot
I would like to generate random convex quadrilaterals using circles, my tutor has suggested to using randomreal to generate 4 numbers and scale the sum of them to 2pi, and then use trigonometry properties to do that, I do not see how that works, can somebody gives some hints about how I should go with it then I can try it out.
graphics parametricplot
graphics parametricplot
asked Dec 16 at 15:05
Chonglin Zhu
666
666
3
"Use trigonometry" means place them on the unit circle. Then connect the dots.
– Daniel Lichtblau
Dec 16 at 15:18
add a comment |
3
"Use trigonometry" means place them on the unit circle. Then connect the dots.
– Daniel Lichtblau
Dec 16 at 15:18
3
3
"Use trigonometry" means place them on the unit circle. Then connect the dots.
– Daniel Lichtblau
Dec 16 at 15:18
"Use trigonometry" means place them on the unit circle. Then connect the dots.
– Daniel Lichtblau
Dec 16 at 15:18
add a comment |
3 Answers
3
active
oldest
votes
Maybe this way?
n = 1000;
x = RandomReal[{0, 2 Pi}, {n, 5}];
x[[All, 2 ;;]] *= Divide[(2. Pi), (x.{0., 1., 1., 1., 1.})];
x = x.UpperTriangularize[ConstantArray[1., {5, 4}]];
quads = Transpose[{Cos[x], Sin[x]}, {3, 1, 2}];
Convexity test:
And @@ (Graphics`PolygonUtils`PolygonConvexQ /@ quads)
True
maybe we only use random four points on the circle and to construct a quadrilateral?
– Chonglin Zhu
Dec 16 at 15:48
Certainly, this is a trivial problem in the sense that it can be tackled in many ways. I just tried to make it fast by using as much vectorized operations and matrix arithmetic as possible. On my machine, the code above generates about 3 million quadrilaterals per second.
– Henrik Schumacher
Dec 16 at 15:59
Thanks, this is very helpful!
– Chonglin Zhu
Dec 16 at 16:00
You're welcome!
– Henrik Schumacher
Dec 16 at 16:00
add a comment |
ClearAll[randomQuad]
randomQuad = SortBy[#, ArcTan @@ # &] & /@ RandomPoint[Circle, {#, 4}] &;
SeedRandom[777]
Graphics[{Circle,
{Opacity[.5], EdgeForm[Gray], RandomColor, Polygon@#} & /@ randomQuad[5]}]
add a comment |
Here's a fun way to use Henrik's stuff (and some other nicely vectorized operations):
n = 550;
x = RandomReal[{0, 2 Pi}, {n, 5}];
x[[All, 2 ;;]] *= Divide[(2. Pi), (x.{0., 1., 1., 1., 1.})];
x = x.UpperTriangularize[ConstantArray[1., {5, 4}]];
quads = Transpose[{Cos[x], Sin[x]}, {3, 1, 2}];
disks = {Range[2, 3], Range[7, 8] , Range[12, 15]};
shiftQuads = quads +
RandomChoice[Flatten@disks, n]*
Transpose[
ConstantArray[{Cos[Subdivide[0., 2. [Pi], n - 1]],
Sin[Subdivide[0., 2. [Pi], n - 1]]}, 4], {2, 3, 1}];
{
Opacity[.15],
Annulus[{0, 0}, {-1, 1} + MinMax@#] & /@ disks,
Thread@{Opacity[.5], RandomColor[n], Thread[Polygon@shiftQuads]}
} // Graphics
Great! I will have a try, so many thanks!
– Chonglin Zhu
Dec 18 at 2:30
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
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%2f187990%2fhow-to-generate-random-convex-quadrilaterals-using-circles-actually-inscribed-w%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
Maybe this way?
n = 1000;
x = RandomReal[{0, 2 Pi}, {n, 5}];
x[[All, 2 ;;]] *= Divide[(2. Pi), (x.{0., 1., 1., 1., 1.})];
x = x.UpperTriangularize[ConstantArray[1., {5, 4}]];
quads = Transpose[{Cos[x], Sin[x]}, {3, 1, 2}];
Convexity test:
And @@ (Graphics`PolygonUtils`PolygonConvexQ /@ quads)
True
maybe we only use random four points on the circle and to construct a quadrilateral?
– Chonglin Zhu
Dec 16 at 15:48
Certainly, this is a trivial problem in the sense that it can be tackled in many ways. I just tried to make it fast by using as much vectorized operations and matrix arithmetic as possible. On my machine, the code above generates about 3 million quadrilaterals per second.
– Henrik Schumacher
Dec 16 at 15:59
Thanks, this is very helpful!
– Chonglin Zhu
Dec 16 at 16:00
You're welcome!
– Henrik Schumacher
Dec 16 at 16:00
add a comment |
Maybe this way?
n = 1000;
x = RandomReal[{0, 2 Pi}, {n, 5}];
x[[All, 2 ;;]] *= Divide[(2. Pi), (x.{0., 1., 1., 1., 1.})];
x = x.UpperTriangularize[ConstantArray[1., {5, 4}]];
quads = Transpose[{Cos[x], Sin[x]}, {3, 1, 2}];
Convexity test:
And @@ (Graphics`PolygonUtils`PolygonConvexQ /@ quads)
True
maybe we only use random four points on the circle and to construct a quadrilateral?
– Chonglin Zhu
Dec 16 at 15:48
Certainly, this is a trivial problem in the sense that it can be tackled in many ways. I just tried to make it fast by using as much vectorized operations and matrix arithmetic as possible. On my machine, the code above generates about 3 million quadrilaterals per second.
– Henrik Schumacher
Dec 16 at 15:59
Thanks, this is very helpful!
– Chonglin Zhu
Dec 16 at 16:00
You're welcome!
– Henrik Schumacher
Dec 16 at 16:00
add a comment |
Maybe this way?
n = 1000;
x = RandomReal[{0, 2 Pi}, {n, 5}];
x[[All, 2 ;;]] *= Divide[(2. Pi), (x.{0., 1., 1., 1., 1.})];
x = x.UpperTriangularize[ConstantArray[1., {5, 4}]];
quads = Transpose[{Cos[x], Sin[x]}, {3, 1, 2}];
Convexity test:
And @@ (Graphics`PolygonUtils`PolygonConvexQ /@ quads)
True
Maybe this way?
n = 1000;
x = RandomReal[{0, 2 Pi}, {n, 5}];
x[[All, 2 ;;]] *= Divide[(2. Pi), (x.{0., 1., 1., 1., 1.})];
x = x.UpperTriangularize[ConstantArray[1., {5, 4}]];
quads = Transpose[{Cos[x], Sin[x]}, {3, 1, 2}];
Convexity test:
And @@ (Graphics`PolygonUtils`PolygonConvexQ /@ quads)
True
edited Dec 16 at 15:55
answered Dec 16 at 15:16
Henrik Schumacher
48.6k467139
48.6k467139
maybe we only use random four points on the circle and to construct a quadrilateral?
– Chonglin Zhu
Dec 16 at 15:48
Certainly, this is a trivial problem in the sense that it can be tackled in many ways. I just tried to make it fast by using as much vectorized operations and matrix arithmetic as possible. On my machine, the code above generates about 3 million quadrilaterals per second.
– Henrik Schumacher
Dec 16 at 15:59
Thanks, this is very helpful!
– Chonglin Zhu
Dec 16 at 16:00
You're welcome!
– Henrik Schumacher
Dec 16 at 16:00
add a comment |
maybe we only use random four points on the circle and to construct a quadrilateral?
– Chonglin Zhu
Dec 16 at 15:48
Certainly, this is a trivial problem in the sense that it can be tackled in many ways. I just tried to make it fast by using as much vectorized operations and matrix arithmetic as possible. On my machine, the code above generates about 3 million quadrilaterals per second.
– Henrik Schumacher
Dec 16 at 15:59
Thanks, this is very helpful!
– Chonglin Zhu
Dec 16 at 16:00
You're welcome!
– Henrik Schumacher
Dec 16 at 16:00
maybe we only use random four points on the circle and to construct a quadrilateral?
– Chonglin Zhu
Dec 16 at 15:48
maybe we only use random four points on the circle and to construct a quadrilateral?
– Chonglin Zhu
Dec 16 at 15:48
Certainly, this is a trivial problem in the sense that it can be tackled in many ways. I just tried to make it fast by using as much vectorized operations and matrix arithmetic as possible. On my machine, the code above generates about 3 million quadrilaterals per second.
– Henrik Schumacher
Dec 16 at 15:59
Certainly, this is a trivial problem in the sense that it can be tackled in many ways. I just tried to make it fast by using as much vectorized operations and matrix arithmetic as possible. On my machine, the code above generates about 3 million quadrilaterals per second.
– Henrik Schumacher
Dec 16 at 15:59
Thanks, this is very helpful!
– Chonglin Zhu
Dec 16 at 16:00
Thanks, this is very helpful!
– Chonglin Zhu
Dec 16 at 16:00
You're welcome!
– Henrik Schumacher
Dec 16 at 16:00
You're welcome!
– Henrik Schumacher
Dec 16 at 16:00
add a comment |
ClearAll[randomQuad]
randomQuad = SortBy[#, ArcTan @@ # &] & /@ RandomPoint[Circle, {#, 4}] &;
SeedRandom[777]
Graphics[{Circle,
{Opacity[.5], EdgeForm[Gray], RandomColor, Polygon@#} & /@ randomQuad[5]}]
add a comment |
ClearAll[randomQuad]
randomQuad = SortBy[#, ArcTan @@ # &] & /@ RandomPoint[Circle, {#, 4}] &;
SeedRandom[777]
Graphics[{Circle,
{Opacity[.5], EdgeForm[Gray], RandomColor, Polygon@#} & /@ randomQuad[5]}]
add a comment |
ClearAll[randomQuad]
randomQuad = SortBy[#, ArcTan @@ # &] & /@ RandomPoint[Circle, {#, 4}] &;
SeedRandom[777]
Graphics[{Circle,
{Opacity[.5], EdgeForm[Gray], RandomColor, Polygon@#} & /@ randomQuad[5]}]
ClearAll[randomQuad]
randomQuad = SortBy[#, ArcTan @@ # &] & /@ RandomPoint[Circle, {#, 4}] &;
SeedRandom[777]
Graphics[{Circle,
{Opacity[.5], EdgeForm[Gray], RandomColor, Polygon@#} & /@ randomQuad[5]}]
edited Dec 17 at 0:15
answered Dec 16 at 15:31
kglr
176k9198404
176k9198404
add a comment |
add a comment |
Here's a fun way to use Henrik's stuff (and some other nicely vectorized operations):
n = 550;
x = RandomReal[{0, 2 Pi}, {n, 5}];
x[[All, 2 ;;]] *= Divide[(2. Pi), (x.{0., 1., 1., 1., 1.})];
x = x.UpperTriangularize[ConstantArray[1., {5, 4}]];
quads = Transpose[{Cos[x], Sin[x]}, {3, 1, 2}];
disks = {Range[2, 3], Range[7, 8] , Range[12, 15]};
shiftQuads = quads +
RandomChoice[Flatten@disks, n]*
Transpose[
ConstantArray[{Cos[Subdivide[0., 2. [Pi], n - 1]],
Sin[Subdivide[0., 2. [Pi], n - 1]]}, 4], {2, 3, 1}];
{
Opacity[.15],
Annulus[{0, 0}, {-1, 1} + MinMax@#] & /@ disks,
Thread@{Opacity[.5], RandomColor[n], Thread[Polygon@shiftQuads]}
} // Graphics
Great! I will have a try, so many thanks!
– Chonglin Zhu
Dec 18 at 2:30
add a comment |
Here's a fun way to use Henrik's stuff (and some other nicely vectorized operations):
n = 550;
x = RandomReal[{0, 2 Pi}, {n, 5}];
x[[All, 2 ;;]] *= Divide[(2. Pi), (x.{0., 1., 1., 1., 1.})];
x = x.UpperTriangularize[ConstantArray[1., {5, 4}]];
quads = Transpose[{Cos[x], Sin[x]}, {3, 1, 2}];
disks = {Range[2, 3], Range[7, 8] , Range[12, 15]};
shiftQuads = quads +
RandomChoice[Flatten@disks, n]*
Transpose[
ConstantArray[{Cos[Subdivide[0., 2. [Pi], n - 1]],
Sin[Subdivide[0., 2. [Pi], n - 1]]}, 4], {2, 3, 1}];
{
Opacity[.15],
Annulus[{0, 0}, {-1, 1} + MinMax@#] & /@ disks,
Thread@{Opacity[.5], RandomColor[n], Thread[Polygon@shiftQuads]}
} // Graphics
Great! I will have a try, so many thanks!
– Chonglin Zhu
Dec 18 at 2:30
add a comment |
Here's a fun way to use Henrik's stuff (and some other nicely vectorized operations):
n = 550;
x = RandomReal[{0, 2 Pi}, {n, 5}];
x[[All, 2 ;;]] *= Divide[(2. Pi), (x.{0., 1., 1., 1., 1.})];
x = x.UpperTriangularize[ConstantArray[1., {5, 4}]];
quads = Transpose[{Cos[x], Sin[x]}, {3, 1, 2}];
disks = {Range[2, 3], Range[7, 8] , Range[12, 15]};
shiftQuads = quads +
RandomChoice[Flatten@disks, n]*
Transpose[
ConstantArray[{Cos[Subdivide[0., 2. [Pi], n - 1]],
Sin[Subdivide[0., 2. [Pi], n - 1]]}, 4], {2, 3, 1}];
{
Opacity[.15],
Annulus[{0, 0}, {-1, 1} + MinMax@#] & /@ disks,
Thread@{Opacity[.5], RandomColor[n], Thread[Polygon@shiftQuads]}
} // Graphics
Here's a fun way to use Henrik's stuff (and some other nicely vectorized operations):
n = 550;
x = RandomReal[{0, 2 Pi}, {n, 5}];
x[[All, 2 ;;]] *= Divide[(2. Pi), (x.{0., 1., 1., 1., 1.})];
x = x.UpperTriangularize[ConstantArray[1., {5, 4}]];
quads = Transpose[{Cos[x], Sin[x]}, {3, 1, 2}];
disks = {Range[2, 3], Range[7, 8] , Range[12, 15]};
shiftQuads = quads +
RandomChoice[Flatten@disks, n]*
Transpose[
ConstantArray[{Cos[Subdivide[0., 2. [Pi], n - 1]],
Sin[Subdivide[0., 2. [Pi], n - 1]]}, 4], {2, 3, 1}];
{
Opacity[.15],
Annulus[{0, 0}, {-1, 1} + MinMax@#] & /@ disks,
Thread@{Opacity[.5], RandomColor[n], Thread[Polygon@shiftQuads]}
} // Graphics
answered Dec 17 at 2:29
b3m2a1
26.7k257154
26.7k257154
Great! I will have a try, so many thanks!
– Chonglin Zhu
Dec 18 at 2:30
add a comment |
Great! I will have a try, so many thanks!
– Chonglin Zhu
Dec 18 at 2:30
Great! I will have a try, so many thanks!
– Chonglin Zhu
Dec 18 at 2:30
Great! I will have a try, so many thanks!
– Chonglin Zhu
Dec 18 at 2:30
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
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%2f187990%2fhow-to-generate-random-convex-quadrilaterals-using-circles-actually-inscribed-w%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
3
"Use trigonometry" means place them on the unit circle. Then connect the dots.
– Daniel Lichtblau
Dec 16 at 15:18