JSCAD User Group

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Regular polygons example

    Comments & Feedback
    2
    3
    1833
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • gilboonet
      gilboonet last edited by

      Hello, I'm making some code examples, here is a regular polygon generator. it can be used to demo the function or make a polygon with it. It can be viewed here
      https://openjscad.org/#https://raw.githubusercontent.com/gilboonet/designs/master/regularPolygons.jscad

      My intention is to do the same for common polyhedrons (icosahedron and so on), so users could start a design from one of those volumes, just by picking the corresponding function.

      I'm using a function (simpleRotate) to rotate my points, but was there a way to use an internal function to do the same ?

      0_1558346448584_Capture d’écran de 2019-05-20 11-59-09.png

      1 Reply Last reply Reply Quote 0
      • gilboonet
        gilboonet last edited by

        This new star primitive looks promising. Thank you for the code sample, I will try to use .fromAngleRadians().

        1 Reply Last reply Reply Quote 0
        • z3dev
          z3dev last edited by z3dev

          There are many ways to do anything. ✌

          The simpleRotate() function isn’t wrong but reminded me of a small piece in the new star primitive (new in V2).

          const getPoints = (vertices, radius, startAngle, center) => {
          var a1 = degToRad(startAngle)
          var a = 2 * Math.PI / vertices
          var points = []
          for (var i = 0; i < vertices; i++) {
          let point = vec2.fromAngleRadians(a * i + a1)
          vec2.scale(point, radius, point)
          vec2.add(point, center, point)
          points.push(point)
          }
          return points
          }

          I hope this provides some encouragement.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB | Contributors