oval() -> ellipse()

This commit is contained in:
Adrian Mariano 2021-11-13 19:45:58 -05:00
parent ed275481b0
commit 0c3c983051
3 changed files with 49 additions and 49 deletions

View file

@ -269,45 +269,45 @@ Which outputs Markdown code that renders like:
The `Function&Module` header is used to document a function which has a related module of the same name. It should have a Description sub-block. It is recommended to also have Usage, Arguments, and Example/Examples sub-blocks. You should have Usage blocks for both calling as a function, and calling as a
module:
// Function&Module: oval()
// Function&Module: ellipse()
// Topics: 2D Shapes, Geometry
// Usage: As a Module
// oval(rx,ry);
// ellipse(rx,ry);
// Usage: As a Function
// path = oval(rx,ry);
// path = ellipse(rx,ry);
// Description:
// When called as a function, returns the perimeter path of the oval.
// When called as a module, creates a 2D oval shape.
// When called as a function, returns the perimeter path of the ellipse.
// When called as a module, creates a 2D ellipse shape.
// Arguments:
// rx = X axis radius.
// ry = Y axis radius.
// Example(2D): Called as a Function
// path = oval(100,60);
// path = ellipse(100,60);
// polygon(path);
// Example(2D): Called as a Module
// oval(80,60);
module oval(rx,ry) {
polygon(oval(rx,ry));
// ellipse(80,60);
module ellipse(rx,ry) {
polygon(ellipse(rx,ry));
}
function oval(rx,ry) =
function ellipse(rx,ry) =
[for (a=[360:-360/$fn:0.0001]) [rx*cos(a),ry*sin(a)];
Which outputs Markdown code that renders like:
> ### Function&Module: oval()
> ### Function&Module: ellipse()
> **Topics:** 2D Shapes, Geometry
>
> **Usage:** As a Module
>
> - oval(rx,ry);
> - ellipse(rx,ry);
>
> **Usage:** As a Function
>
> - path = oval(rx,ry);
> - path = ellipse(rx,ry);
>
> **Description:**
> When called as a function, returns the perimeter path of the oval.
> When called as a module, creates a 2D oval shape.
> When called as a function, returns the perimeter path of the ellipse.
> When called as a module, creates a 2D ellipse shape.
>
> **Arguments:**
> Positional Arg | What it does
@ -318,7 +318,7 @@ Which outputs Markdown code that renders like:
> **Example:** Called as a Function
>
> ```openscad
> path = oval(100,60);
> path = ellipse(100,60);
> polygon(path);
> ```
> GENERATED IMAGE SHOWN HERE
@ -326,7 +326,7 @@ Which outputs Markdown code that renders like:
> **Example:** Called as a Module
>
> ```openscad
> oval(80,60);
> ellipse(80,60);
> ```
> GENERATED IMAGE SHOWN HERE
@ -385,18 +385,18 @@ Usage Block
The Usage block describes the various ways that the current function or module can be called, with the names of the arguments. By convention, the first few arguments that can be called positionally just have their name shown. The remaining arguments that should be passed by name, will have the name followed by an `=` (equal sign). Arguments that are optional in the given Usage context are shown in `<` and `>` angle brackets:
// Usage: As a Module
// oval(rx, ry, <spin=>);
// ellipse(rx, ry, <spin=>);
// Usage: As a Function
// path = oval(rx, ry, <spin=>);
// path = ellipse(rx, ry, <spin=>);
Which outputs Markdown code that renders like:
> **Usage:** As a Module
> - oval(rx, ry, <spin=>);
> - ellipse(rx, ry, <spin=>);
>
> **Usage:** As a Function
>
> - path = oval(rx, ry, <spin=>);
> - path = ellipse(rx, ry, <spin=>);
Description Block

View file

@ -179,7 +179,7 @@ function rect(size=1, center, rounding=0, chamfer=0, anchor, spin=0) =
// circle(r|d=, ...) { attachables }
// Usage: As a Function
// path = circle(r|d=, ...);
// See Also: oval()
// See Also: ellipse()
// Description:
// When called as the builtin module, creates a 2D polygon that approximates a circle of the given size.
// When called as a function, returns a 2D list of points (path) for a polygon that approximates a circle of the given size.
@ -212,41 +212,41 @@ module circle(r, d, anchor=CENTER, spin=0) {
// Function&Module: oval()
// Function&Module: ellipse()
// Usage: As a Module
// oval(r|d=, [realign=], [circum=], ...);
// ellipse(r|d=, [realign=], [circum=], ...);
// Usage: With Attachments
// oval(r|d=, [realign=], [circum=], ...) { attachables }
// ellipse(r|d=, [realign=], [circum=], ...) { attachables }
// Usage: As a Function
// path = oval(r|d=, [realign=], [circum=], ...);
// path = ellipse(r|d=, [realign=], [circum=], ...);
// Topics: Shapes (2D), Paths (2D), Path Generators, Attachable
// See Also: circle()
// Description:
// When called as a module, creates a 2D polygon that approximates a circle or ellipse of the given size.
// When called as a function, returns a 2D list of points (path) for a polygon that approximates a circle or ellipse of the given size.
// Note that the point list or shape is the same as the one you would get by scaling the output of {{circle()}}, but with this module your
// attachments to the oval will
// attachments to the ellipse will
// Arguments:
// r = Radius of the circle or pair of semiaxes of oval
// r = Radius of the circle or pair of semiaxes of ellipse
// ---
// d = Diameter of the circle or a pair giving the full X and Y axis lengths.
// realign = If true, rotates the polygon that approximates the circle/oval by half of one size.
// realign = If true, rotates the polygon that approximates the circle/ellipse by half of one size.
// circum = If true, the polygon that approximates the circle will be upsized slightly to circumscribe the theoretical circle. If false, it inscribes the theoretical circle. Default: false
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0`
// Example(2D): By Radius
// oval(r=25);
// ellipse(r=25);
// Example(2D): By Diameter
// oval(d=50);
// ellipse(d=50);
// Example(2D): Anchoring
// oval(d=50, anchor=FRONT);
// ellipse(d=50, anchor=FRONT);
// Example(2D): Spin
// oval(d=50, anchor=FRONT, spin=45);
// ellipse(d=50, anchor=FRONT, spin=45);
// Example(NORENDER): Called as Function
// path = oval(d=50, anchor=FRONT, spin=45);
module oval(r, d, realign=false, circum=false, anchor=CENTER, spin=0) {
// path = ellipse(d=50, anchor=FRONT, spin=45);
module ellipse(r, d, realign=false, circum=false, anchor=CENTER, spin=0) {
r = get_radius(r=r, d=d, dflt=1);
dummy = assert((is_finite(r) || is_vector(r,2)) && all_positive(r), "Invalid radius or diameter for oval");
dummy = assert((is_finite(r) || is_vector(r,2)) && all_positive(r), "Invalid radius or diameter for ellipse");
sides = segs(max(r));
sc = circum? (1 / cos(180/sides)) : 1;
rx = default(r[0],r) * sc;
@ -270,7 +270,7 @@ module oval(r, d, realign=false, circum=false, anchor=CENTER, spin=0) {
}
function oval(r, d, realign=false, circum=false, anchor=CENTER, spin=0) =
function ellipse(r, d, realign=false, circum=false, anchor=CENTER, spin=0) =
let(
r = get_radius(r=r, d=d, dflt=1),
sides = segs(max(r)),
@ -290,7 +290,7 @@ function oval(r, d, realign=false, circum=false, anchor=CENTER, spin=0) =
// regular_ngon(n, ir=/id=, [realign=]);
// regular_ngon(n, side=, [realign=]);
// Topics: Shapes (2D), Paths (2D), Path Generators, Attachable
// See Also: circle(), pentagon(), hexagon(), octagon(), oval(), star()
// See Also: circle(), pentagon(), hexagon(), octagon(), ellipse(), star()
// Description:
// When called as a function, returns a 2D path for a regular N-sided polygon.
// When called as a module, creates a 2D regular N-sided polygon.
@ -353,7 +353,7 @@ function regular_ngon(n=6, r, d, or, od, ir, id, side, rounding=0, realign=false
!is_undef(align_side)? rot(from=RIGHT, to=point2d(align_side), planar=true) * rot(180/n, planar=true) :
affine2d_identity()
),
path4 = rounding==0? oval(r=r, $fn=n) : (
path4 = rounding==0? ellipse(r=r, $fn=n) : (
let(
steps = floor(segs(r)/n),
step = 360/n/steps,
@ -426,7 +426,7 @@ module regular_ngon(n=6, r, d, or, od, ir, id, side, rounding=0, realign=false,
// pentagon(ir=|id=, [realign=]);
// pentagon(side=, [realign=]);
// Topics: Shapes (2D), Paths (2D), Path Generators, Attachable
// See Also: circle(), regular_ngon(), hexagon(), octagon(), oval(), star()
// See Also: circle(), regular_ngon(), hexagon(), octagon(), ellipse(), star()
// Description:
// When called as a function, returns a 2D path for a regular pentagon.
// When called as a module, creates a 2D regular pentagon.
@ -490,7 +490,7 @@ module pentagon(r, d, or, od, ir, id, side, rounding=0, realign=false, align_tip
// path = hexagon(ir=/id=, ...);
// path = hexagon(side=, ...);
// Topics: Shapes (2D), Paths (2D), Path Generators, Attachable
// See Also: circle(), regular_ngon(), pentagon(), octagon(), oval(), star()
// See Also: circle(), regular_ngon(), pentagon(), octagon(), ellipse(), star()
// Description:
// When called as a function, returns a 2D path for a regular hexagon.
// When called as a module, creates a 2D regular hexagon.
@ -554,7 +554,7 @@ module hexagon(r, d, or, od, ir, id, side, rounding=0, realign=false, align_tip,
// path = octagon(ir=/id=, ...);
// path = octagon(side=, ...);
// Topics: Shapes (2D), Paths (2D), Path Generators, Attachable
// See Also: circle(), regular_ngon(), pentagon(), hexagon(), oval(), star()
// See Also: circle(), regular_ngon(), pentagon(), hexagon(), ellipse(), star()
// Description:
// When called as a function, returns a 2D path for a regular octagon.
// When called as a module, creates a 2D regular octagon.
@ -763,7 +763,7 @@ module trapezoid(h, w1, w2, angle, shift=0, chamfer=0, rounding=0, anchor=CENTER
// path = star(n, r/or, ir, [realign=], [align_tip=], [align_pit=], ...);
// path = star(n, r/or, step=, ...);
// Topics: Shapes (2D), Paths (2D), Path Generators, Attachable
// See Also: circle(), oval()
// See Also: circle(), ellipse()
// Description:
// When called as a function, returns the path needed to create a star polygon with N points.
// When called as a module, creates a star polygon with N points.
@ -1020,7 +1020,7 @@ function teardrop2d(r, ang=45, cap_h, d, anchor=CENTER, spin=0) =
// Usage: As Function
// path = glued_circles(r/d=, [spread=], [tangent=], ...);
// Topics: Shapes (2D), Paths (2D), Path Generators, Attachable
// See Also: circle(), oval()
// See Also: circle(), ellipse()
// Description:
// When called as a function, returns a 2D path forming a shape of two circles joined by curved waist.
// When called as a module, creates a 2D shape of two circles joined by curved waist.
@ -1090,7 +1090,7 @@ function _superformula(theta,m1,m2,n1,n2=1,n3=1,a=1,b=1) =
// Usage: As Function
// path = supershape(step, [m1=], [m2=], [n1=], [n2=], [n3=], [a=], [b=], <r=/d=>);
// Topics: Shapes (2D), Paths (2D), Path Generators, Attachable
// See Also: circle(), oval()
// See Also: circle(), ellipse()
// Description:
// When called as a function, returns a 2D path for the outline of the [Superformula](https://en.wikipedia.org/wiki/Superformula) shape.
// When called as a module, creates a 2D [Superformula](https://en.wikipedia.org/wiki/Superformula) shape.

View file

@ -47,11 +47,11 @@ module test_trapezoid() {
test_trapezoid();
module test_oval() {
assert_approx(oval(d=100,$fn=24), [[50,0],[48.2962913145,-12.9409522551],[43.3012701892,-25],[35.3553390593,-35.3553390593],[25,-43.3012701892],[12.9409522551,-48.2962913145],[0,-50],[-12.9409522551,-48.2962913145],[-25,-43.3012701892],[-35.3553390593,-35.3553390593],[-43.3012701892,-25],[-48.2962913145,-12.9409522551],[-50,0],[-48.2962913145,12.9409522551],[-43.3012701892,25],[-35.3553390593,35.3553390593],[-25,43.3012701892],[-12.9409522551,48.2962913145],[0,50],[12.9409522551,48.2962913145],[25,43.3012701892],[35.3553390593,35.3553390593],[43.3012701892,25],[48.2962913145,12.9409522551]]);
assert_approx(oval(d=[100,80],$fn=24), [[50,0],[48.2962913145,-10.3527618041],[43.3012701892,-20],[35.3553390593,-28.2842712475],[25,-34.6410161514],[12.9409522551,-38.6370330516],[0,-40],[-12.9409522551,-38.6370330516],[-25,-34.6410161514],[-35.3553390593,-28.2842712475],[-43.3012701892,-20],[-48.2962913145,-10.3527618041],[-50,0],[-48.2962913145,10.3527618041],[-43.3012701892,20],[-35.3553390593,28.2842712475],[-25,34.6410161514],[-12.9409522551,38.6370330516],[0,40],[12.9409522551,38.6370330516],[25,34.6410161514],[35.3553390593,28.2842712475],[43.3012701892,20],[48.2962913145,10.3527618041]]);
module test_ellipse() {
assert_approx(ellipse(d=100,$fn=24), [[50,0],[48.2962913145,-12.9409522551],[43.3012701892,-25],[35.3553390593,-35.3553390593],[25,-43.3012701892],[12.9409522551,-48.2962913145],[0,-50],[-12.9409522551,-48.2962913145],[-25,-43.3012701892],[-35.3553390593,-35.3553390593],[-43.3012701892,-25],[-48.2962913145,-12.9409522551],[-50,0],[-48.2962913145,12.9409522551],[-43.3012701892,25],[-35.3553390593,35.3553390593],[-25,43.3012701892],[-12.9409522551,48.2962913145],[0,50],[12.9409522551,48.2962913145],[25,43.3012701892],[35.3553390593,35.3553390593],[43.3012701892,25],[48.2962913145,12.9409522551]]);
assert_approx(ellipse(d=[100,80],$fn=24), [[50,0],[48.2962913145,-10.3527618041],[43.3012701892,-20],[35.3553390593,-28.2842712475],[25,-34.6410161514],[12.9409522551,-38.6370330516],[0,-40],[-12.9409522551,-38.6370330516],[-25,-34.6410161514],[-35.3553390593,-28.2842712475],[-43.3012701892,-20],[-48.2962913145,-10.3527618041],[-50,0],[-48.2962913145,10.3527618041],[-43.3012701892,20],[-35.3553390593,28.2842712475],[-25,34.6410161514],[-12.9409522551,38.6370330516],[0,40],[12.9409522551,38.6370330516],[25,34.6410161514],[35.3553390593,28.2842712475],[43.3012701892,20],[48.2962913145,10.3527618041]]);
}
test_oval();
test_ellipse();
module test_star() {