Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I manage to create a circle inside triangle with this code, but circle inside other polygons are not maximum size:

var p1 = board.create("point", [0.0, 2.0]);
var p2 = board.create("point", [2.0, 1.0]);

//var pol = board.create("regularpolygon", [p1, p2, 3]);
var pol = board.create("regularpolygon", [p1, p2, 4]);
//var pol = board.create("regularpolygon", [p1, p2, 5]);

board.create("incircle", pol.vertices);

What is the easiest way to draw a maximum circle inside square and pentagon?

How about smallest circle around the polygon?

share|improve this question
this question should be on stackoverflow. – Hermann Ingjaldsson Sep 27 '13 at 14:12
Yea, I realized it later, but on the other hand John gave a good answer for it. I'm happy either way, solutions given in general way to a specific problem, or specific example given to a general problem. Anything can help. – MarkokraM Oct 1 '13 at 6:22
up vote 8 down vote accepted

This is why geometry class in high school had you spending all that time drawing stuff.

Assuming a regular polygon (all sides same length, all "corners" same angle), it is immediately obvious that the centers of the largest inscribed circle and the smallest circumscribed circle are identical, and are given by the vector arithmetic mean of the polygon vertices.

The smallest inscribed circle touches the polygon at the midpoint of each edge. The radius is thus given by the distance from the center to the midpoint of any one edge of the polygon.

The smallest circumscribed circle touches the polygon at every vertex. The radius is the distance from the center to any one vertex of the polygon.

share|improve this answer
+1 and "good on you" for explaining the solution rather than giving code. – Marjan Venema Sep 26 '13 at 9:59
That's how I figured it out. I'm providing correct code on my own answer, but accept your answer as a solution :) – MarkokraM Sep 26 '13 at 12:27
// two points for the side of the polygon
var p1 = board.create("point", [0.0, 0.0], point_props);
var p2 = board.create("point", [4.0, 0.0], point_props);

// square polygon has 4 regular sides
var pl = board.create("regularpolygon", [p1, p2, 4]);

// center point of the polygon
var cp = board.create("circumcenter", pl.vertices);

// for incircle get middle point of the side
var mp = board.create("midpoint", [p1, p2]);
board.create("circle", [cp, mp]);

// for outcircle use either p1 or p2
board.create("circle", [cp, p1]);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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