• Cannot be empty
    Cannot be empty
    Number of sides must be a number greater than 2
    Radius must be greater than zero"
  • How it Works
    
    export function polygon(input) {
      var cx = parseInt(input.cx); //center x
      var cy = parseInt(input.cy); //center y
      var n = input.n; //number of sides
      var r = input.r; //radius. Dist from center to a vertex
      var startAng;
      var ang, vx, vy;
    
      n = Math.round(n);
      var centerAng = (2 * Math.PI) / n;
    
      startAng = (Math.PI * input.a) / 180;
    
      function isOdd(n) {
        return n % 2 == 1;
      }
    
      //calculate the default start angle
    
      if (input.a.length == 0) {
        //none supplied
        if (isOdd(n)) startAng = Math.PI / 2;
        //12 oclock
        else startAng = Math.PI / 2 - centerAng / 2;
      }
    
      //create a vertex array
      var vertex = new Array();
      for (var i = 0; i < n; i++) {
        ang = startAng + i * centerAng;
        vx = Math.round(cx + r * Math.cos(ang));
        vy = Math.round(cy - r * Math.sin(ang));
        vertex.push({ x: vx, y: vy });
      }
      return vertex;
    }
      
  • About the calculator

    This calculator takes the parameters of a regular polygon and calculates its coordinates. It produces both the coordinates of the vertices and the coordinates of the line segments making up the sides of the polygon. It is useful to blind users and those who produce material for the sight-impaired. The programs that emboss shapes on pages for the blind need the coordinates of the lines that make up the shape. This page was designed to make it easy to produce the data needed by those programs (such as SVG Draw) to 'draw' regular polygons.

    Click the 'Calculate' button to refresh the results. Note that the y coordinates are positive downwards, to conform to the convention in most computer software. Positive x is to the right. The sides output is a table containing the start and end x,y coordinates of each side of the polygon, going counter clockwise from the first one. Below that is the same data in CSV format. The vertex output is a table containing the x and y coordinates of each vertex of the polygon, going counter clockwise from the first one. Below that is the same data in CSV format.

    • Center X and center Y are the coordinates of the center point of the polygon. Set initially to 0, 0. Note that the y coordinate is positive downwards, to conform to the convention in most computer software. Positive x is to the right.
    • The number of sides. Must be greater than 2. Set initially to 4.
    • The radius is the distance from the center to a vertex. Set initially to 50.
    • Start angle is the position of the first vertex. This angle is in degrees and is the angle starting at 3 o'clock going counter clockwise. So for example if you want the first vertex to be at 12 o'clock, set this to 90. Set initially to blank (auto). If you leave this blank it will be set automatically: If the number of sides is odd, (e.g. a pentagon), the first vertex will be at 12 o'clock. If even, e.g. an octagon, the top and bottom sides will be horizontal on the page.