JSCAD User Group
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Regular polygons example

    Scheduled Pinned Locked Moved Comments & Feedback
    3 Posts 2 Posters 2.4k Views 1 Watching
    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.
    • gilboonetG Offline
      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
      • z3devZ Offline
        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
        • gilboonetG Offline
          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

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post
          Powered by NodeBB | Contributors