function to create regular polygon
-
Hello, I'm making a design made from a polyhedron and am needing to make regular polygons having same side length. I have a V1 script to do that and before to port it to V2, I was wondering whether it could be done straightly using
a function to compute the radius depending on the side length and the number of segments.
Do you thing such function is possible ?function RegularPolygon(sideLength, sidesCount){ let R = ... return circle ({radius: R, segments: sidesCount}) }But on the other side, maybe is it better to stop using the segment trick, and by the way, I remember that there is star(), but isn't there it's counterpart that would create regular polygon ?
-
@gilboonet not sure if this is what u need

αangle of the triangle isMath.PI/sidesCountin radians or360/sidesCount/2in degrees
red line isA = Math.sin(α)
blue line isA=Math.cos(α)
the radius you are looking for the circle isR=1in this drawingR=sideLength/2/Math.sin(α)
or
sideLength=(R*Math.sin(α)) * 2const jscad = require('@jscad/modeling') // https://openjscad.xyz/docs/module-modeling_primitives.html const { circle } = jscad.primitives function main({// @jscad-params sideLength = 15, sidesCount = 6, }){ let alpha = Math.PI / sidesCount let R = sideLength/2/Math.sin(alpha) // R === sideLength in case of sideCount=6 (hexagon) console.log('R',R) return circle({radius:R, segments: sidesCount}) } module.exports = {main} -
@hrgdavor Thanks a lot that's exactly what I needed,

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