omdl  v0.6.1
OpenSCAD Mechanical Design Library
2d Shapes

Two-dimensional geometric shapes. More...

+ Collaboration diagram for 2d Shapes:

Files

file  shapes2d.scad
 Two-dimensional basic shapes.
 

Functions

module rectangle (size, vr, vrm=0, center=false)
 A rectangle with edge, fillet, and/or chamfer corners. More...
 
module rectangle_c (size, core, t, co, cr=0, vr, vr1, vr2, vrm=0, vrm1, vrm2, center=false)
 A rectangle with a removed rectangular core. More...
 
module rhombus (size, vr, center=false)
 A rhombus. More...
 
module triangle_ppp (v1, v2, v3, vr, v1r, v2r, v3r, centroid=false, incenter=false)
 A general triangle specified by three vertices. More...
 
module triangle_lp (v, vr, centroid=false, incenter=false)
 A general triangle specified by a list of its three vertices. More...
 
module triangle_sss (s1, s2, s3, vr, v1r, v2r, v3r, centroid=false, incenter=false)
 A general triangle specified by its three side lengths. More...
 
module triangle_ls (v, vr, centroid=false, incenter=false)
 A general triangle specified by a list of its three side lengths. More...
 
module triangle_ls_c (vs, vc, co, cr=0, vr, vr1, vr2, centroid=false, incenter=false)
 A general triangle specified by its sides with a removed triangular core. More...
 
module triangle_sas (s1, a, s2, x=1, vr, v1r, v2r, v3r, centroid=false, incenter=false)
 A general triangle specified by two sides and the included angle. More...
 
module triangle_asa (a1, s, a2, x=1, vr, v1r, v2r, v3r, centroid=false, incenter=false)
 A general triangle specified by a side and two adjacent angles. More...
 
module triangle_aas (a1, a2, s, x=1, vr, v1r, v2r, v3r, centroid=false, incenter=false)
 A general triangle specified by a side, one adjacent angle and the opposite angle. More...
 
module triangle_ss (x, y, vr, v1r, v2r, v3r, centroid=false, incenter=false)
 A right-angled triangle specified by its opposite and adjacent side lengths. More...
 
module triangle_sa (x, y, aa, oa, vr, v1r, v2r, v3r, centroid=false, incenter=false)
 A right-angled triangle specified by a side length and an angle. More...
 
module ngon (n, r, vr)
 An n-sided equiangular/equilateral regular polygon. More...
 
module ellipse (size)
 An ellipse. More...
 
module ellipse_c (size, core, t, co, cr=0)
 An ellipse with a removed elliptical core. More...
 
module ellipse_s (size, a1=0, a2=0)
 An ellipse sector. More...
 
module ellipse_cs (size, core, t, a1=0, a2=0, co, cr=0)
 A sector of an ellipse with a removed elliptical core. More...
 
module star2d (size, n=5, vr)
 A two-dimensional star. More...
 

Detailed Description

Two-dimensional geometric shapes.

Function Documentation

module ellipse ( size  )

An ellipse.

Parameters
size<decimal-list-2|decimal> A list [rx, ry] of decimals or a single decimal for (rx=ry).

Example

shapes2d_dim_qvga_top_ellipse.png
ellipse
1  ellipse( size=[25, 40] );

Definition at line 1103 of file shapes2d.scad.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

module ellipse_c ( size  ,
core  ,
,
co  ,
cr  = 0 
)

An ellipse with a removed elliptical core.

Parameters
size<decimal-list-2|decimal> A list [rx, ry] of decimals or a single decimal for (rx=ry).
core<decimal-list-2|decimal> A list [rx, ry] of decimals or a single decimal for (rx=ry).
t<decimal-list-2|decimal> A list [x, y] of decimals or a single decimal for (x=y).
co<decimal-list-2> Core offset. A list [x, y] of decimals.
cr<decimal> Core z-rotation.

Thickness t

  • core = size - t; when t and size are given.
  • size = core + t; when t and core are given.

Example

shapes2d_dim_qvga_top_ellipse_c.png
ellipse_c
1  ellipse_c( size=[25,40], core=[16,10], co=[0,10], cr=45 );

Definition at line 1144 of file shapes2d.scad.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

module ellipse_cs ( size  ,
core  ,
,
a1  = 0,
a2  = 0,
co  ,
cr  = 0 
)

A sector of an ellipse with a removed elliptical core.

Parameters
size<decimal-list-2|decimal> A list [rx, ry] of decimals or a single decimal for (rx=ry).
core<decimal-list-2|decimal> A list [rx, ry] of decimals or a single decimal for (rx=ry).
t<decimal-list-2|decimal> A list [x, y] of decimals or a single decimal for (x=y).
a1<decimal> The start angle in degrees.
a2<decimal> The stop angle in degrees.
co<decimal-list-2> Core offset. A list [x, y] of decimals.
cr<decimal> Core z-rotation.

Thickness t

  • core = size - t; when t and size are given.
  • size = core + t; when t and core are given.

Example

shapes2d_dim_qvga_top_ellipse_cs.png
ellipse_cs
1  ellipse_cs( size=[25,40], t=[10,5], a1=90, a2=180, co=[10,0], cr=45);

Definition at line 1254 of file shapes2d.scad.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

module ellipse_s ( size  ,
a1  = 0,
a2  = 0 
)

An ellipse sector.

Parameters
size<decimal-list-2|decimal> A list [rx, ry] of decimals or a single decimal for (rx=ry).
a1<decimal> The start angle in degrees.
a2<decimal> The stop angle in degrees.

Example

shapes2d_dim_qvga_top_ellipse_s.png
ellipse_s
1  ellipse_s( size=[25,40], a1=90, a2=180 );

Definition at line 1186 of file shapes2d.scad.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

module ngon ( ,
,
vr   
)

An n-sided equiangular/equilateral regular polygon.

Parameters
n<integer> The number of sides.
r<decimal> The ngon vertex radius.
vr<decimal> The vertex rounding radius.

Example

shapes2d_dim_qvga_top_ngon.png
ngon
1  ngon( n=6, r=25, vr=6 );

See Wikipedia for more information.

Definition at line 1069 of file shapes2d.scad.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

module rectangle ( size  ,
vr  ,
vrm  = 0,
center  = false 
)

A rectangle with edge, fillet, and/or chamfer corners.

Parameters
size<decimal-list-2|decimal> A list [x, y] of decimals or a single decimal for (x=y).
vr<decimal-list-4|decimal> The corner rounding radius. A list [v1r, v2r, v3r, v4r] of decimals or a single decimal for (v1r=v2r=v3r=v4r). Unspecified corners are not rounded.
vrm<integer> The corner radius mode. A 4-bit encoded integer that indicates each corner finish. Use bit value 0 for fillet and 1 for chamfer.
center<boolean> Center about origin.

Example

shapes2d_dim_qvga_top_rectangle.png
rectangle
1  rectangle( size=[25,40], vr=[0,10,10,5], vrm=4, center=true );

Note
A corner fillet replaces an edge with a quarter circle of radius vr, inset [vr, vr] from the corner vertex.
A corner chamfer replaces an edge with an isosceles right triangle with side lengths equal to the corresponding corner rounding radius vr. Therefore the chamfer length will be vr*sqrt(2) at 45 degree angles.

Definition at line 117 of file shapes2d.scad.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

module rectangle_c ( size  ,
core  ,
,
co  ,
cr  = 0,
vr  ,
vr1  ,
vr2  ,
vrm  = 0,
vrm1  ,
vrm2  ,
center  = false 
)

A rectangle with a removed rectangular core.

Parameters
size<decimal-list-2|decimal> A list [x, y] of decimals or a single decimal for (x=y).
core<decimal-list-2|decimal> A list [x, y] of decimals or a single decimal for (x=y).
t<decimal-list-2|decimal> A list [x, y] of decimals or a single decimal for (x=y).
co<decimal-list-2> Core offset. A list [x, y] of decimals.
cr<decimal> Core z-rotation.
vr<decimal-list-4|decimal> The default corner rounding radius. A list [v1r, v2r, v3r, v4r] of decimals or a single decimal for (v1r=v2r=v3r=v4r). Unspecified corners are not rounded.
vr1<decimal-list-4|decimal> The outer corner rounding radius.
vr2<decimal-list-4|decimal> The core corner rounding radius.
vrm<integer> The default corner radius mode. A 4-bit encoded integer that indicates each corner finish. Use bit value 0 for fillet and 1 for chamfer.
vrm1<integer> The outer corner radius mode.
vrm2<integer> The core corner radius mode.
center<boolean> Center about origin.

Thickness t

  • core = size - t; when t and size are given.
  • size = core + t; when t and core are given.

Example

shapes2d_dim_qvga_top_rectangle_c.png
rectangle_c
1  rectangle_c( size=[40,25], t=[15,5], vr1=[0,0,10,10], vr2=2.5, vrm2=3, co=[0,5], center=true );

Definition at line 237 of file shapes2d.scad.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

module rhombus ( size  ,
vr  ,
center  = false 
)

A rhombus.

Parameters
size<decimal-list-2|decimal> A list [w, h] of decimals or a single decimal for (w=h).
vr<decimal-list-4|decimal> The corner rounding radius. A list [v1r, v2r, v3r, v4r] of decimals or a single decimal for (v1r=v2r=v3r=v4r). Unspecified corners are not rounded.
center<boolean> Center about origin.

Example

shapes2d_dim_qvga_top_rhombus.png
rhombus
1  rhombus( size=[40,25], vr=[2,4,2,4], center=true );

See Wikipedia for more information.

Definition at line 302 of file shapes2d.scad.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

module star2d ( size  ,
= 5,
vr   
)

A two-dimensional star.

Parameters
size<decimal-list-2|decimal> A list [l, w] of decimals or a single decimal for (size=l=2*w).
n<decimal> The number of points.
vr<decimal-list-3|decimal> The vertex rounding radius. A list [v1r, v2r, v3r] of decimals or a single decimal for (v1r=v2r=v3r).

Example

shapes2d_dim_qvga_top_star2d.png
star2d
1  star2d( size=[40, 15], n=5, vr=2 );

Definition at line 1301 of file shapes2d.scad.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

module triangle_aas ( a1  ,
a2  ,
,
= 1,
vr  ,
v1r  ,
v2r  ,
v3r  ,
centroid  = false,
incenter  = false 
)

A general triangle specified by a side, one adjacent angle and the opposite angle.

Parameters
a1<decimal> The opposite angle 1 in degrees.
a2<decimal> The adjacent angle 2 in degrees.
s<decimal> The side length.
x<integer> The side to draw on the positive x-axis (x=1 for s).
vr<decimal> The default vertex rounding radius.
v1r<decimal> Vertex 1 rounding radius.
v2r<decimal> Vertex 2 rounding radius.
v3r<decimal> Vertex 3 rounding radius.
centroid<boolean> Center centroid at origin.
incenter<boolean> Center incenter at origin.

Example

shapes2d_dim_qvga_top_triangle_aas.png
triangle_aas
1  triangle_aas( a1=60, a2=30, s=40, vr=2, centroid=true );

See Wikipedia for more information.

Definition at line 896 of file shapes2d.scad.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

module triangle_asa ( a1  ,
,
a2  ,
= 1,
vr  ,
v1r  ,
v2r  ,
v3r  ,
centroid  = false,
incenter  = false 
)

A general triangle specified by a side and two adjacent angles.

Parameters
a1<decimal> The adjacent angle 1 in degrees.
s<decimal> The side length adjacent to the angles.
a2<decimal> The adjacent angle 2 in degrees.
x<integer> The side to draw on the positive x-axis (x=1 for s).
vr<decimal> The default vertex rounding radius.
v1r<decimal> Vertex 1 rounding radius.
v2r<decimal> Vertex 2 rounding radius.
v3r<decimal> Vertex 3 rounding radius.
centroid<boolean> Center centroid at origin.
incenter<boolean> Center incenter at origin.

Example

shapes2d_dim_qvga_top_triangle_asa.png
triangle_asa
1  triangle_asa( a1=30, s=50, a2=60, vr=2, centroid=true );

See Wikipedia for more information.

Definition at line 811 of file shapes2d.scad.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

module triangle_lp ( ,
vr  ,
centroid  = false,
incenter  = false 
)

A general triangle specified by a list of its three vertices.

Parameters
v<point-2d-list-3> A list [v1, v2, v3] of points [x, y].
vr<decimal-list-3|decimal> The vertex rounding radius. A list [v1r, v2r, v3r] of decimals or a single decimal for (v1r=v2r=v3r).
centroid<boolean> Center centroid at origin.
incenter<boolean> Center incenter at origin.

Example

t = triangle_sss2lp( 30, 40, 50 );
r = [2, 4, 6];
triangle_lp( v=t, vr=r );

Definition at line 480 of file shapes2d.scad.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

module triangle_ls ( ,
vr  ,
centroid  = false,
incenter  = false 
)

A general triangle specified by a list of its three side lengths.

Parameters
v<decimal-list-3> A list [s1, s2, s3] of decimals.
vr<decimal-list-3|decimal> The vertex rounding radius. A list [v1r, v2r, v3r] of decimals or a single decimal for (v1r=v2r=v3r).
centroid<boolean> Center centroid at origin.
incenter<boolean> Center incenter at origin.

Example

t = triangle_sss2lp( 3, 4, 5 );
s = triangle_lp2ls( t );
triangle_ls( v=s, vr=2, centroid=true );

Definition at line 591 of file shapes2d.scad.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

module triangle_ls_c ( vs  ,
vc  ,
co  ,
cr  = 0,
vr  ,
vr1  ,
vr2  ,
centroid  = false,
incenter  = false 
)

A general triangle specified by its sides with a removed triangular core.

Parameters
vs<decimal-list-3|decimal> The size. A list [s1, s2, s3] of decimals or a single decimal for (s1=s2=s3).
vc<decimal-list-3|decimal> The core. A list [s1, s2, s3] of decimals or a single decimal for (s1=s2=s3).
co<decimal-list-2> Core offset. A list [x, y] of decimals.
cr<decimal> Core z-rotation.
vr<decimal-list-3|decimal> The default vertex rounding radius. A list [v1r, v2r, v3r] of decimals or a single decimal for (v1r=v2r=v3r).
vr1<decimal-list-3|decimal> The outer vertex rounding radius.
vr2<decimal-list-3|decimal> The core vertex rounding radius.
centroid<boolean> Center centroid at origin.
incenter<boolean> Center incenter at origin.

Example

shapes2d_dim_qvga_top_triangle_ls_c.png
triangle_ls_c
1  triangle_ls_c( vs=[30,50,50], vc=[20,40,40], co=[0,-4], vr1=[1,1,6], vr2=4, centroid=true );

Note
The outer and inner triangles centroids are aligned prior to the core removal.

Definition at line 646 of file shapes2d.scad.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

module triangle_ppp ( v1  ,
v2  ,
v3  ,
vr  ,
v1r  ,
v2r  ,
v3r  ,
centroid  = false,
incenter  = false 
)

A general triangle specified by three vertices.

Parameters
v1<point-2d> A point [x, y] for vertex 1.
v2<point-2d> A point [x, y] for vertex 2.
v3<point-2d> A point [x, y] for vertex 3.
vr<decimal> The default vertex rounding radius.
v1r<decimal> Vertex 1 rounding radius.
v2r<decimal> Vertex 2 rounding radius.
v3r<decimal> Vertex 3 rounding radius.
centroid<boolean> Center centroid at origin.
incenter<boolean> Center incenter at origin.

Example

shapes2d_dim_qvga_top_triangle_ppp.png
triangle_ppp
1  triangle_ppp( v1=[0,0], v2=[5,25], v3=[40,5], vr=2, centroid=true );

Warning
Currently, in order to round any vertex, all must be given a rounding radius, either via vr or individually.
Todo:

Replace the hull() operation with calculated tangential intersection of the rounded vertexes.

Remove the all or nothing requirement for vertex rounding.

Definition at line 403 of file shapes2d.scad.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

module triangle_sa ( ,
,
aa  ,
oa  ,
vr  ,
v1r  ,
v2r  ,
v3r  ,
centroid  = false,
incenter  = false 
)

A right-angled triangle specified by a side length and an angle.

Parameters
x<decimal> The length of the side along the x-axis.
y<decimal> The length of the side along the y-axis.
aa<decimal> The adjacent angle in degrees.
oa<decimal> The opposite angle in degrees.
vr<decimal> The default vertex rounding radius.
v1r<decimal> Vertex 1 rounding radius.
v2r<decimal> Vertex 2 rounding radius.
v3r<decimal> Vertex 3 rounding radius.
centroid<boolean> Center centroid at origin.
incenter<boolean> Center incenter at origin.

Example

shapes2d_dim_qvga_top_triangle_sa.png
triangle_sa
1  triangle_sa( x=40, aa=30, vr=2, centroid=true );

Note
When both x and y are given, both triangles are rendered.
When both aa and oa are given, aa is used.

Definition at line 1016 of file shapes2d.scad.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

module triangle_sas ( s1  ,
,
s2  ,
= 1,
vr  ,
v1r  ,
v2r  ,
v3r  ,
centroid  = false,
incenter  = false 
)

A general triangle specified by two sides and the included angle.

Parameters
s1<decimal> The length of the side 1.
a<decimal> The included angle in degrees.
s2<decimal> The length of the side 2.
x<integer> The side to draw on the positive x-axis (x=1 for s1).
vr<decimal> The default vertex rounding radius.
v1r<decimal> Vertex 1 rounding radius.
v2r<decimal> Vertex 2 rounding radius.
v3r<decimal> Vertex 3 rounding radius.
centroid<boolean> Center centroid at origin.
incenter<boolean> Center incenter at origin.

Example

shapes2d_dim_qvga_top_triangle_sas.png
triangle_sas
1  triangle_sas( s1=50, a=60, s2=30, vr=2, centroid=true );

See Wikipedia for more information.

Definition at line 740 of file shapes2d.scad.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

module triangle_ss ( ,
,
vr  ,
v1r  ,
v2r  ,
v3r  ,
centroid  = false,
incenter  = false 
)

A right-angled triangle specified by its opposite and adjacent side lengths.

Parameters
x<decimal> The length of the side along the x-axis.
y<decimal> The length of the side along the y-axis.
vr<decimal> The default vertex rounding radius.
v1r<decimal> Vertex 1 rounding radius.
v2r<decimal> Vertex 2 rounding radius.
v3r<decimal> Vertex 3 rounding radius.
centroid<boolean> Center centroid at origin.
incenter<boolean> Center incenter at origin.

Example

shapes2d_dim_qvga_top_triangle_ss.png
triangle_ss
1  triangle_ss( x=30, y=40, vr=2, centroid=true );

Definition at line 973 of file shapes2d.scad.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

module triangle_sss ( s1  ,
s2  ,
s3  ,
vr  ,
v1r  ,
v2r  ,
v3r  ,
centroid  = false,
incenter  = false 
)

A general triangle specified by its three side lengths.

Parameters
s1<decimal> The length of the side 1 (along the x-axis).
s2<decimal> The length of the side 2.
s3<decimal> The length of the side 3.
vr<decimal> The default vertex rounding radius.
v1r<decimal> Vertex 1 rounding radius.
v2r<decimal> Vertex 2 rounding radius.
v3r<decimal> Vertex 3 rounding radius.
centroid<boolean> Center centroid at origin.
incenter<boolean> Center incenter at origin.

Example

shapes2d_dim_qvga_top_triangle_sss.png
triangle_sss
1  triangle_sss( s1=30, s2=40, s3=50, vr=2, centroid=true );

See Wikipedia for more information.

Definition at line 530 of file shapes2d.scad.

+ Here is the call graph for this function:

+ Here is the caller graph for this function: