mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-09 16:26:47 +02:00
added shape_cyclicpolygon
This commit is contained in:
@@ -83,6 +83,7 @@ Too many dependencies? Because OpenSCAD doesn't provide namespace management, I
|
||||
- [shape_ellipse](https://openhome.cc/eGossip/OpenSCAD/lib-shape_ellipse.html)
|
||||
- [shape_square](https://openhome.cc/eGossip/OpenSCAD/lib-shape_square.html)
|
||||
- [shape_trapezium](https://openhome.cc/eGossip/OpenSCAD/lib-shape_trapezium.html)
|
||||
- [shape_cyclicpolygon](https://openhome.cc/eGossip/OpenSCAD/lib-shape_cyclicpolygon.html)
|
||||
- [shape_pentagram](https://openhome.cc/eGossip/OpenSCAD/lib-shape_pentagram.html)
|
||||
- [shape_superformula](https://openhome.cc/eGossip/OpenSCAD/lib-shape_superformula.html)
|
||||
|
||||
|
BIN
docs/images/lib-shape_cyclicpolygon-1.JPG
Normal file
BIN
docs/images/lib-shape_cyclicpolygon-1.JPG
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
BIN
docs/images/lib-shape_cyclicpolygon-2.JPG
Normal file
BIN
docs/images/lib-shape_cyclicpolygon-2.JPG
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
58
docs/lib-shape_cyclicpolygon.md
Normal file
58
docs/lib-shape_cyclicpolygon.md
Normal file
@@ -0,0 +1,58 @@
|
||||
# shape_cyclicpolygon
|
||||
|
||||
Returns shape points of a regular cyclic polygon. They can be used with xxx_extrude modules of dotSCAD. The shape points can be also used with the built-in polygon module.
|
||||
|
||||
## Parameters
|
||||
|
||||
- `sides` : The radius of the circle.
|
||||
- `circle_r` : The radius of the circumcircle.
|
||||
- `$fa`, `$fs`, `$fn` : Check [the circle module](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_the_2D_Subsystem#circle) for more details.
|
||||
|
||||
## Examples
|
||||
|
||||
include <shape_cyclicpolygon.scad>;
|
||||
|
||||
circle_r = 10;
|
||||
corner_r = 3;
|
||||
|
||||
$fn = 24;
|
||||
|
||||
for(i = [0:2]) {
|
||||
translate([i * circle_r * 2, 0, 0])
|
||||
polygon(
|
||||
shape_cyclicpolygon(
|
||||
sides = 3 + i,
|
||||
circle_r = circle_r,
|
||||
corner_r = corner_r
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
for(i = [0:2]) {
|
||||
translate([i * circle_r * 2, -circle_r * 2, 0])
|
||||
polygon(
|
||||
shape_cyclicpolygon(
|
||||
sides = 4 + i,
|
||||
circle_r = circle_r ,
|
||||
corner_r = corner_r
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||

|
||||
|
||||
include <shape_cyclicpolygon.scad>;
|
||||
include <rotate_p.scad>;
|
||||
include <cross_sections.scad>;
|
||||
include <polysections.scad>;
|
||||
include <ring_extrude.scad>;
|
||||
|
||||
shape_pts = shape_cyclicpolygon(
|
||||
sides = 5,
|
||||
circle_r = 10,
|
||||
corner_r = 3
|
||||
);
|
||||
|
||||
ring_extrude(shape_pts, radius = 20, angle = 180, twist = 90);
|
||||
|
||||

|
55
src/shape_cyclicpolygon.scad
Normal file
55
src/shape_cyclicpolygon.scad
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* shape_cyclicpolygon.scad
|
||||
*
|
||||
* Returns shape points of a regular cyclic polygon.
|
||||
* They can be used with xxx_extrude modules of dotSCAD.
|
||||
* The shape points can be also used with the built-in polygon module.
|
||||
*
|
||||
* @copyright Justin Lin, 2017
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
* @see https://openhome.cc/eGossip/OpenSCAD/lib-shape_cyclicpolygon.html
|
||||
*
|
||||
**/
|
||||
|
||||
include <__private__/__frags.scad>;
|
||||
include <__private__/__pie_for_rounding.scad>;
|
||||
|
||||
function shape_cyclicpolygon(sides, circle_r, corner_r) =
|
||||
let(
|
||||
frag_a = 360 / sides,
|
||||
corner_a = (180 - frag_a),
|
||||
corner_circle_a = 180 - corner_a,
|
||||
half_corner_circle_a = corner_circle_a / 2,
|
||||
corner_circle_center = circle_r - corner_r / sin(corner_a / 2),
|
||||
first_corner = [
|
||||
for(
|
||||
pt = __pie_for_rounding(
|
||||
corner_r,
|
||||
-half_corner_circle_a,
|
||||
half_corner_circle_a,
|
||||
__frags(corner_r) * corner_circle_a / 360
|
||||
)
|
||||
)
|
||||
[pt[0] + corner_circle_center, pt[1]]
|
||||
]
|
||||
|
||||
)
|
||||
concat(
|
||||
first_corner,
|
||||
[
|
||||
for(side = [1:sides - 1])
|
||||
for(pt = first_corner)
|
||||
let(
|
||||
a = frag_a * side,
|
||||
x = pt[0],
|
||||
y = pt[1],
|
||||
sina = sin(a),
|
||||
cosa = cos(a)
|
||||
)
|
||||
[
|
||||
x * cosa - y * sina,
|
||||
x * sina + y * cosa
|
||||
]
|
||||
]
|
||||
);
|
Reference in New Issue
Block a user