Last active
July 4, 2021 20:47
-
-
Save mjparme/77226387ede529895b55aef575c9dbdd to your computer and use it in GitHub Desktop.
Generate an Oval
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getOvalPoints(numOfPoints = 16, width = 4, height = 1, degreesAround = 360) = [ | |
| let(degreesPerPoint = degreesAround / numOfPoints) | |
| for (point = [0 : numOfPoints - 1]) | |
| let(angle = degreesPerPoint * point) | |
| ovalPoint(angle, width, height) | |
| ]; | |
| //returns [x,y] position of point given height and width of oval | |
| function ovalPoint(angle, width, height) = | |
| [height * sin(angle), width * cos(angle)]; | |
| module polyline(points, thickness = 2, connectLastToFirst = false, pointShape = "circle") { | |
| vectorLength = len(points); | |
| echo("PolyLine Points: ", points); | |
| echo("VectorLength: ", vectorLength); | |
| for (i = [0 : vectorLength - 1]) { | |
| //We don't draw a point again if there isn't a point after it, but do need to check if we need to | |
| //connect the last point to the first point | |
| if (points[i + 1] != undef) { | |
| drawLine(points[i], points[i + 1], thickness); | |
| } else { | |
| if (connectLastToFirst) { | |
| drawLine(points[0], points[len(points) - 1], thickness); | |
| } | |
| } | |
| } | |
| module drawLine(point1, point2, thickness) { | |
| hull() { | |
| radius = thickness / 2; | |
| if (pointShape == "circle") { | |
| translate(point1) circle(radius); | |
| translate(point2) circle(radius); | |
| } else { | |
| translate(point1) sphere(radius); | |
| translate(point2) sphere(radius); | |
| } | |
| } | |
| } | |
| } | |
| $fn = 60; | |
| polyline(getOvalPoints(numOfPoints = 64, width = 100, height = 50), connectLastToFirst = true, pointShape = "sphere"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment