# 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.

• "Use trigonometry" means place them on the unit circle. Then connect the dots. – Daniel Lichtblau Dec 16 '18 at 15:18

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 @@ (GraphicsPolygonUtilsPolygonConvexQ /@ quads)


True

• maybe we only use random four points on the circle and to construct a quadrilateral? – Chonglin Zhu Dec 16 '18 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 '18 at 15:59
• Thanks, this is very helpful! – Chonglin Zhu Dec 16 '18 at 16:00
• You're welcome! – Henrik Schumacher Dec 16 '18 at 16:00
ClearAll[randomQuad]
randomQuad = SortBy[#, ArcTan @@ # &] & /@ RandomPoint[Circle[], {#, 4}] &;

SeedRandom[777]
Graphics[{Circle[],
{Opacity[.5], EdgeForm[Gray], RandomColor[], Polygon@#} & /@ randomQuad[5]}]


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]};