4 Replies Latest reply on Nov 23, 2015 1:38 PM by Qwertyfly...

    Custom Angled Polygons

    arteangelus Level 1


      I would like to create cairo-pentagon tiling.

      Cairo pentagonal tiling - Wikipedia, the free encyclopedia


      Last year I had asked about custom angled triangle, gladly someone had helped me but now I'm facing with a problem to create different angled polygons in illustrator. Of course it can be done manually but I would like to create lots of tilings like cairo pattern. For example it has 5 sides and their angles are 120, 90,90,120,120.

      A Script would be great which allows populating an input box with these numbers and creates such polygons.


      By the way last year CarlosCanto had helped me and his polygonal script was : (This script creates polygons with custom length and side numbers.What I need at this point is entering custom angles. If it's hard to create number of sides option additionally  it would be still handy to have pentagon script with custom angles. Thank you for your help.


      #target Illustrator
      // script.name = polygonBySide.jsx;
      // script.description = creates a polygone based on side length;
      // script.required = an open document;
      // script.parent = CarlosCanto; // 11/21/13;
      // script.elegant = false;
      // Shared via Creativetuts.com – Author : Carlos Canto
      if (app.documents.length>0) polygonBySide ();
      else alert (“no document to draw the polygon”);
      function polygonBySide() {
      var title = “Create Polygon by Side”;
      var sideLen = Number(prompt (“Enter Side Length in Points”, 20, title));
      var numberOfSides = Number(prompt (“Enter number of sides”, 5, title));
      //var s = 2*r*Math.sin(Math.PI/n); // side length = 2*radius*sin(180 deg/number of sides)
      var radius = sideLen/(2*Math.sin(Math.PI/numberOfSides));
      var idoc = app.activeDocument;
      var ctr = idoc.activeView.centerPoint;
      dw = idoc.width;
      dh = idoc.height;
      wc= dw /2;
      hc = dh *-0.5;
      var ipoly = idoc.pathItems.polygon (ctr[0], ctr[1], radius, numberOfSides);
      ipoly.position = Array(wc-(ipoly.width/2),hc+(ipoly.height/2));
        • 1. Re: Custom Angled Polygons
          Qwertyfly... Level 4

          something like this will draw the shape you want.

          but it would be quite a task to allow user to enter all the angles etc..


          var L = 100;
          var Sx = 100, Sy = -100, h = L/2, g = Math.sqrt(3)*h;
          var points = {
              a : [Sx,Sy],
              b : [Sx+g,Sy+h],
              c : [Sx+g+g,Sy],
              d : [Sx+g+g-h,Sy-g],
              e : [Sx+h,Sy-g]
          var doc = app.activeDocument;
          var shape = doc.pathItems.add();
          shape.closed = true;
          shape.filled = false;
          shape.stroked = true;
          shape.strokeWidth = 1;


          here is a visual of your shape.

          it can be broken down to 4 triangles all the same and a rectangle.

          all the triangles are 30-60-90's so the math is quite simple.


          Edit: sorry, in the script I use "h" and "g" for the triangle not "a" and "b" like the below diagram.

                  also, point.a is the left most point and it works clockwise around the shape.



          • 2. Re: Custom Angled Polygons
            arteangelus Level 1

            Thanks a lot, it worked,...

            Still it would be great to have a script with custom angle input boxes and sides...if any coders would help I would appreciate it.


            • 3. Re: Custom Angled Polygons
              williamadowling Level 4

              That's sort of a big job. If you're looking for someone to write that code for you, I'd suggest offering payment for such a task. We're all about helping out around here, but when you just want an entire script written, especially one as intensive as you're asking for, it's good to respect the time and talent of of whoever ends up writing your code.


              Just my $.02

              • 4. Re: Custom Angled Polygons
                Qwertyfly... Level 4

                how would you envision this working.

                needs to know number of sides, each angle, length of each side.

                then you need to worry about all the angles adding up correctly to bring the shape full circle.

                and if the lengths of each side are not 100% correct the shape will not close.


                even for a competent coder this is a big task and would take much time to just get a handle on how to get it to work.


                3 sides is a total of 180°

                4 sides 360°

                5 sides 540°

                6 sides 720°



                I have not even thought how you would deal with the side length