Regular polygons example



  • 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



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


  • administrators

    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.