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.jscadMy 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 ?

-
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.
-
This new star primitive looks promising. Thank you for the code sample, I will try to use .fromAngleRadians().
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