Let us consider a regular n-sided polygon where all of the sides are equal in length with n being a natural number larger than or equal to three. All of the vertices lie on the unit circle (circle of radius one centered at the origin) and one of the vertices is always at the coordinate (x,y)=(1,0). Now let's draw all possible diagonals (including the edges) which connect all n vertices to one another. Here is an example for n=11.

enter image description here

This results in n-choose-2 (which is just n(n-1)/2) lines (diagonals and edges) which in this case is 55. The total number of line intersections, counting the interior intersection points as well as the n vertices, will be denoted I and I=341 in this case.

The Goal

Your goal is to write a full program or a function which takes in an integer n larger than or equal to three and outputs a list of (x,y) coordinates of all of the intersections of all of the diagonals and edges, that are contained within the regular n-sided polygon with one of its vertices being at (1,0). This includes the n vertices themselves which lie on the unit circle. The length of this list must be I. There is an OEIS sequence for I, which is A007569 and here is a paper which talks about it.

Rules and Specifications

  1. Standard loopholes are forbidden.

  2. Each coordinate has to be an ordered 2-tuple, giving the (x,y) coordinates in the Cartesian system.

  3. The list of coordinates can be in any order. It doesn't have to be sorted or in any particular order.

  4. All of the coordinates provided must be accurate to at least six significant figures. I am not specifying a rounding method. You are free to choose any rounding method or to simply chop off a number. Also for n large enough, it will be the case that two distinct intersections (in exact arithmetic) will be equal to each other to six significant figures in both coordinates (in floating point arithmetic). In this case you are free to treat them as the "same" and remove the "duplicates" from your list. The length of your list will be less than I, but oh well!

  5. The coordinates can be in decimal or scientific notation. For small enough n, decimal notation is fine and decimal notation will make it easier to check so it is preferred. But I am not mandating one over the other.

  6. Outputting I, which should be the length of your coordinate list, is not a requirement for this task. You don't have to output it.

You can assume whatever input/output form that is appropriate for your language. You can also assume that the input will always be a positive integer greater than or equal to three. In case of any other input, your program is free to do whatever it wants. You can also assume that the input and output will always be in the numerical range of your language/environment. Trailing newlines are okay in the output.

Some Test Cases

I am showing more significant digits here than I need to. You are only required to show six. Remember, you don't have to print I.

n => 3

I => 3

n => 4

I => 5

n => 5

I => 10

n => 6

I => 19

n => 7

I => 42

I can provide more test cases but they will take up a lot of space and I am not sure how to provide them here. Let me know if you guys need more cases and what is the best way for me to provide them.


This is code-golf. The answer with the smallest byte-count will win. In case of a tie, I will pick the answer that was posted earlier as the winner.

Please post your answer in the standard format with all compiler/interpreter options/flags.

  • \$\begingroup\$ Are three-line intersections (such as the center of the hexagon) counted once or twice? \$\endgroup\$
    – Luis Mendo
    Sep 28, 2017 at 10:28
  • \$\begingroup\$ @LuisMendo No matter how many lines intersect at a point, the point is only counted once. \$\endgroup\$ Sep 28, 2017 at 15:46

2 Answers 2


Python 3, 211 204 bytes

from itertools import*
lambda n:{(round(z.real,6),round(z.imag,6))
          for z in[(a*b*c+a*b*d-a*c*d-b*c*d)/(a*b-c*d)
          for(a,b),(c,d)in C(C([23.140693**(2j*k/n)for k in range(n)],2),2)]
          if abs(z)<=1}

For readability I've added superfluous newlines in my answer that aren't included in the bytecount.

If we have a line crossing through points a and b, and another line crossing through points c and d, where a, b, c, d are complex numbers, then the intersection between those lines (not segments!) is


But for a point u on the unit circle, the conjugate of u is 1/u. Then the formula simplifies to:


Now, if the intersection of the two lines also lies within the unit circle, that's a proper intersection of the diagonals.


Mathematica 165 143 112 bytes

53 bytes saved by Misha Lavrov! 22 thanks to his suggestion to use Cases instead of Select. 31 additional bytes saved thanks to his suggestion to use CirclePoints.


Table[{Cos[Pi/2+(2k Pi)/# ],Sin[Pi/2+(2k Pi)/# ]},{k,0,#-1}] generates the coordinates of the vertices of a regular polygon (inscribed in the unit circle) with one vertex at (0,1).

Line segments are then defined for each subsets of possible pairs of those coordinates.

RegionIntersection finds a point of intersection for each pair of these line segments (iff such intersection exists).
Cases[... Point@{x_} :> x] returns the coordinates. Cases in which two segments do not intersect are ignored.

Union eliminates possible duplicates.

Example (n=7)

(s = Subsets; 
 RegionIntersection @@@s[Line /@s[N[{1, Pi/2}~CirclePoints~#&@#, {2}], {2}], 
Point@{x_} :> x]) &[7]

{{-0.974928, -0.222521}, {-0.781831, 0.62349}, {-0.674671, 0.153989}, {-0.62698, -0.0549581}, {-0.588735, -0.222521}, \ {-0.541044, -0.431468}, {-0.541044, 0.321552}, {-0.433884, -0.900969}, {-0.433884, 0.455927}, {-0.347948, -0.524459}, {-0.347948, 0.0794168}, {-0.300257, 0.62349}, {-0.279032, -0.222521}, {-0.240787, -0.0549581}, \ {-0.193096, -0.599031}, {-0.193096, 0.153989}, {-0.154851, 0.321552}, {-0.10716, -0.222521}, {-0.085936, 0.62349}, {0., -0.692021}, {0., -0.356896}, {0., 0.24698}, {0., 1.}, {0.085936, 0.62349}, {0.10716, -0.222521}, {0.154851, 0.321552}, {0.193096, -0.599031}, {0.193096, 0.153989}, {0.240787, -0.0549581}, {0.279032, -0.222521}, {0.300257, 0.62349}, {0.347948, -0.524459}, {0.347948, 0.0794168}, {0.433884, -0.900969}, {0.433884, 0.455927}, {0.541044, -0.431468}, {0.541044, 0.321552}, {0.588735, -0.222521}, {0.62698, -0.0549581}, {0.674671, 0.153989}, {0.781831, 0.62349}, {0.974928, -0.222521}}

Graphics[{PointSize[Large], Blue, Point@%}, Axes -> True]


  • \$\begingroup\$ We can simplify thing somewhat by using Cases instead of Select. Change Select[...,Head@#==Point&] to Cases[...,Point@_] and, as a bonus, we can do the wrapper-removal at the same time by making it Cases[...,Point@{x_}->x]. \$\endgroup\$ Sep 29, 2017 at 3:21
  • \$\begingroup\$ Also, there's a built-in CirclePoints: CirclePoints[#] or CirclePoints@# will get us n evenly spaced points around the unit circle, and CirclePoints[{1,Pi/2},#] or {1,Pi/2}~CirclePoints~# will get us n points rotated so that (1,0) is included. \$\endgroup\$ Sep 29, 2017 at 3:23
  • \$\begingroup\$ @MishaLavrov, First use I've seen of CirclePoints with rotation. You clearly examined the code carefully. Thanks \$\endgroup\$
    – DavidC
    Sep 29, 2017 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.