<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[function to create regular polygon]]></title><description><![CDATA[<p dir="auto">Hello, I'm making a design made from a polyhedron and am needing to make regular polygons having same side length. I have a <a href="https://3d.hrg.hr/jscad/V1/#https://raw.githubusercontent.com/gilboonet/designs/master/regularPolygons.jscad" rel="nofollow ugc">V1 script</a> to do that and before to port it to V2, I was wondering whether it could be done straightly using<br />
a function to compute the radius depending on the side length and the number of segments.<br />
Do you thing such function is possible ?</p>
<pre><code>function RegularPolygon(sideLength, sidesCount){
  let R = ...
return circle ({radius: R, segments: sidesCount})
}
</code></pre>
<p dir="auto">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 ?</p>
]]></description><link>https://openjscad.nodebb.com/topic/322/function-to-create-regular-polygon</link><generator>RSS for Node</generator><lastBuildDate>Sun, 15 Mar 2026 05:30:52 GMT</lastBuildDate><atom:link href="https://openjscad.nodebb.com/topic/322.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 01 Dec 2021 09:32:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to function to create regular polygon on Wed, 01 Dec 2021 10:25:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://openjscad.nodebb.com/uid/152">@hrgdavor</a> Thanks a lot that's exactly what I needed,<br />
<img src="/assets/uploads/files/1638354289644-capture-d-%C3%A9cran-de-2021-12-01-11-24-28.png" alt="Capture d’écran de 2021-12-01 11-24-28.png" class=" img-responsive img-markdown" /></p>
]]></description><link>https://openjscad.nodebb.com/post/1026</link><guid isPermaLink="true">https://openjscad.nodebb.com/post/1026</guid><dc:creator><![CDATA[gilboonet]]></dc:creator><pubDate>Wed, 01 Dec 2021 10:25:14 GMT</pubDate></item><item><title><![CDATA[Reply to function to create regular polygon on Wed, 01 Dec 2021 10:07:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://openjscad.nodebb.com/uid/5">@gilboonet</a> not sure if this is what u need<br />
<img src="/assets/uploads/files/1638352166727-7094d8db-ba0c-4bb1-8b49-8401b616acee-image.png" alt="7094d8db-ba0c-4bb1-8b49-8401b616acee-image.png" class=" img-responsive img-markdown" /></p>
<p dir="auto"><code>α</code> angle of the triangle is <code>Math.PI/sidesCount</code> in radians or <code>360/sidesCount/2</code> in degrees<br />
red line is <code>A = Math.sin(α)</code><br />
blue line is <code>A=Math.cos(α)</code><br />
the radius you are looking for the circle is<code>R=1</code> in this drawing</p>
<p dir="auto"><code>R=sideLength/2/Math.sin(α)</code><br />
or<br />
<code>sideLength=(R*Math.sin(α)) * 2</code></p>
<pre><code class="language-js">
const 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}

</code></pre>
]]></description><link>https://openjscad.nodebb.com/post/1025</link><guid isPermaLink="true">https://openjscad.nodebb.com/post/1025</guid><dc:creator><![CDATA[hrgdavor]]></dc:creator><pubDate>Wed, 01 Dec 2021 10:07:49 GMT</pubDate></item></channel></rss>