omdl  v1.0
OpenSCAD Mechanical Design Library
Polygons

Roundable polygons generated in 2D space. More...

+ Collaboration diagram for Polygons:

Files

file  polygon.scad
 Roundable polygons generated in 2D space.
 

Round edge

module pg_corner_round (r=1, m=1, o=origin2d, v1=x_axis2d_uv, v2=y_axis2d_uv)
 A polygon edge round with constant radius between two vectors. More...
 

Round side general

module pg_rectangle_rs (size=1, o, sr, center=false)
 A polygon rectangle with side rounding. More...
 

Round vertex general

module pg_elliptical_sector (r=1, o=origin2d, v1=x_axis2d_uv, v2=x_axis2d_uv, s=true)
 A polygon elliptical sector. More...
 
module pg_trapezoid (b=1, h, l=1, a=90, o=origin2d, vr, vrm=1, vfn, center=false)
 A polygon trapezoid with individual vertex rounding and arc facets. More...
 
module pg_rectangle (size=1, o, vr, vrm=1, vfn, center=false)
 A polygon rectangle with vertex rounding. More...
 
module pg_rhombus (size=1, o, vr, vrm=1, vfn, center=false)
 A polygon rhombus with vertex rounding. More...
 
module pg_ngon (n=5, r=1, o, vr, vrm=1, vfn, center=true)
 A n-sided regular polygon with vertex rounding. More...
 

Round vertex triangles

module pg_triangle_ppp (c, o, vr, vrm=1, vfn, cm=0)
 A polygon triangle specified by three coordinate points with vertex rounding. More...
 
module pg_triangle_sss (v, a=x_axis_ci, o, vr, vrm=1, vfn, cm=0)
 A polygon triangle specified by three side lengths with vertex rounding. More...
 
module pg_triangle_sas (v, a=x_axis_ci, o, vr, vrm=1, vfn, cm=0)
 A polygon triangle specified by size-angle-size with vertex rounding. More...
 
module pg_triangle_asa (v, a=x_axis_ci, o, vr, vrm=1, vfn, cm=0)
 A polygon triangle specified by angle-size-angle with vertex rounding. More...
 
module pg_triangle_aas (v, a=x_axis_ci, o, vr, vrm=1, vfn, cm=0)
 A polygon triangle specified by angle-angle-size with vertex rounding. More...
 

Usage Details

Roundable polygons generated in 2D space.

Requires:
include <omdl-base.scad>;
Polygons
IIIIII
pg_corner_round()
pg_elliptical_sector()
pg_ngon()
IVVVI
pg_rectangle()
pg_rectangle_rs()
pg_rhombus()
VIIVIIIIX
pg_trapezoid()
pg_triangle_aas()
pg_triangle_asa()
XXIXII
pg_triangle_ppp()
pg_triangle_sas()
pg_triangle_sss()

Function and/or Module Documentation

◆ pg_corner_round()

module pg_corner_round ( = 1,
= 1,
= origin2d,
v1  = x_axis2d_uv,
v2  = y_axis2d_uv 
)

A polygon edge round with constant radius between two vectors.

Parameters
r<decimal> The round radius.
m<integer> The round mode.
o<point-2d> The vertex coordinate [x, y] at which the two edge vectors meet (the corner being rounded).
v1<line-2d | decimal> The first edge direction. A 2d line, vector, or decimal angle.
v2<line-2d | decimal> The second edge direction. A 2d line, vector, or decimal angle.
fn<integer> The number of facets (optional).
cw<boolean> Coordinate point ordering. When true the list runs from the inflection point on edge 1 toward the inflection point on edge 2; when false the order is reversed.
Returns
<points-2d> A list of coordinates points [[x, y], ...] beginning at the inflection point on v1, followed by the arc (or chamfer) segment, and ending at the inflection point on v2. These points replace the original corner vertex in a polygon path.

Computes the replacement coordinate sequence for a single polygon corner at o between edges v1 and v2. Normally, edge angle 1 should be less than edge angle 2.

The round mode may be one of the following:

mode name description
1 fillet concave arc (inward, tangent to both edges)
2 round convex arc (outward, tangent to both edges)
3 chamfer straight bevel between the two inflection points

Object example

pg_corner_round( r=20, v1=[1,1], v2=135 );
module pg_corner_round(r=1, m=1, o=origin2d, v1=x_axis2d_uv, v2=y_axis2d_uv)
A polygon edge round with constant radius between two vectors.
Definition: polygon.scad:564
pg_corner_round

Definition at line 563 of file polygon.scad.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pg_rectangle_rs()

module pg_rectangle_rs ( size  = 1,
,
sr  ,
center  = false 
)

A polygon rectangle with side rounding.

Parameters
size<decimal-list-2 | decimal> A list [x, y] of decimals or a single decimal for (x=y).
o<point-2d> The origin offset coordinate [x, y].
sr<decimal-list-2 | decimal> The side rounding radius.
center<boolean> Center about origin.

The side rounding radius may be zero, positive, or negative. When positive, the rounding arc is swept clockwise. When negative, the arc is swept counter clockwise. A positive radius must be greater than the side length. The arch center point is located along a line that starts at the mid-point of the side vertices and extends perpendicularly by the radius distance. The arch is swept about the center point with constant radius from one vertex to the next.

Object example

pg_rectangle_rs( [60,30], sr=[60,-100], center=true );
module pg_rectangle_rs(size=1, o, sr, center=false)
A polygon rectangle with side rounding.
Definition: polygon.scad:616
pg_rectangle_rs

Definition at line 615 of file polygon.scad.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pg_elliptical_sector()

module pg_elliptical_sector ( = 1,
= origin2d,
v1  = x_axis2d_uv,
v2  = x_axis2d_uv,
= true 
)

A polygon elliptical sector.

Parameters
r<decimal-list-2 | decimal> The elliptical radius. A list [rx, ry] of decimals where rx is the x-axis radius and ry is the y-axis radius, or a single decimal for (rx=ry).
o<point-2d> The center coordinate [x, y].
v1<line-2d | decimal> The sector angle 1. A 2d line, vector, or decimal.
v2<line-2d | decimal> The sector angle 2. A 2d line, vector, or decimal.
s<boolean> Use signed vector angle conversions. When false, positive angle conversion will be used.
fn<integer> The number of facets (optional).
cw<boolean> Coordinate point ordering. When true the returned list is in the natural computed order; when false the list is reversed.
Returns
<points-2d> A list of coordinates points [[x, y], ...].

The coordinates sweep from angle v1 to angle v2. When v1 and v2 are equal, a full ellipse is returned. The sweep direction is determined by the signs of the angles; a positive delta sweeps counter-clockwise and a negative delta sweeps clockwise, regardless of the cw ordering parameter (which only controls whether the returned list is reversed).

When v1 and v2 are not equal, the origin point o is prepended to the coordinate list, forming a closed pie-sector shape when passed directly to polygon(). For a full ellipse, o is omitted and the result is a closed ring of perimeter points.

The parameter s controls how vector angles are converted to decimal degrees. When s = true (default), signed angle conversion is used, so vectors below the x-axis yield negative angles. When s = false, all angles are mapped to [0, 360). This affects sector orientation when v1 or v2 are given as 2d lines or vectors rather than explicit decimal angles.

When fn is undefined, its value is determined by get_fn().

Object example

pg_elliptical_sector( r=[20, 15], v1=115, v2=-115 );
module pg_elliptical_sector(r=1, o=origin2d, v1=x_axis2d_uv, v2=x_axis2d_uv, s=true)
A polygon elliptical sector.
Definition: polygon.scad:685
pg_elliptical_sector

Definition at line 684 of file polygon.scad.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pg_trapezoid()

module pg_trapezoid ( = 1,
,
= 1,
= 90,
= origin2d,
vr  ,
vrm  = 1,
vfn  ,
center  = false 
)

A polygon trapezoid with individual vertex rounding and arc facets.

Parameters
b<decimal-list-2 | decimal> The base lengths. A list [b1, b2] of 2 decimals or a single decimal for (b1=b2).
h<decimal> The perpendicular height between bases. Takes precedence over l when both are specified. When neither h nor l is specified, l defaults to 1.
l<decimal> The left side leg length. Used only when h is not specified; the resulting height is l × sin(a).
a<decimal> The angle in degrees between the lower base and the left leg. When h is specified, restricted to [45, 135] to keep the upper-left vertex above the lower base.
o<point-2d> The origin offset coordinate [x, y].
cw<boolean> Polygon vertex ordering.
Returns
<points-2d> A list of exactly 4 coordinate points [[x, y], ...] defining the trapezoid vertices.

The four vertices are computed from the origin o as follows: p1 = o (lower-left), p2 = upper-left leg endpoint, p3 = p2 + [b2, 0] (upper-right), p4 = o + [b1, 0] (lower-right). The lower base has length b1 and the upper base has length b2.

When both h and l are specified, h takes precedence and the actual leg length is derived from h and a. When only l is given, the perpendicular height is l × sin(a). If h is specified, the angle a is restricted to the range [45, 135] to keep the upper-left vertex above the lower base.

Special cases: when b is a single decimal (b1 = b2) and a = 90 the result is a rectangle; when additionally b1 = h the result is a square. When a ≠ 90 and b1 = b2 the result is a parallelogram.

See Wikipedia for more general information on trapezoids.

Parameters
vr<decimal-list-4 | decimal> The vertices rounding radius.
vrm<integer-list-4 | integer> The vertices rounding mode.
vfn<integer-list-4> The vertices arc fragment number.
center<boolean> Center origin at trapezoid centroid.

Each vertex may be assigned an individual rounding radius, rounding mode, and facet number as described in polygon_round_eve_all_p by using the parameters: vr, vrm, and vfn. When vr is undefined, no rounding is performed on the polygon vertices.

Object example

pg_trapezoid( b=[50,20], l=25, a=45, vr=2, center=true);
module pg_trapezoid(b=1, h, l=1, a=90, o=origin2d, vr, vrm=1, vfn, center=false)
A polygon trapezoid with individual vertex rounding and arc facets.
Definition: polygon.scad:724
pg_trapezoid

Definition at line 723 of file polygon.scad.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pg_rectangle()

module pg_rectangle ( size  = 1,
,
vr  ,
vrm  = 1,
vfn  ,
center  = false 
)

A polygon rectangle with vertex rounding.

Parameters
size<decimal-list-2 | decimal> A list [x, y] of decimals or a single decimal for (x=y).
o<point-2d> The origin offset coordinate [x, y].
vr<decimal-list-4 | decimal> The vertices rounding radius.
vrm<integer-list-4 | integer> The vertices rounding mode.
vfn<integer-list-4> The vertices arc fragment number.
center<boolean> Center about origin.

Each vertex may be assigned an individual rounding radius, rounding mode, and facet number as described in polygon_round_eve_all_p by using the parameters: vr, vrm, and vfn. When vr is undefined, no rounding is performed on the polygon vertices.

Object example

pg_rectangle( size=[30,10], vr=2, center=true );
module pg_rectangle(size=1, o, vr, vrm=1, vfn, center=false)
A polygon rectangle with vertex rounding.
Definition: polygon.scad:773
pg_rectangle

Definition at line 772 of file polygon.scad.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pg_rhombus()

module pg_rhombus ( size  = 1,
,
vr  ,
vrm  = 1,
vfn  ,
center  = false 
)

A polygon rhombus with vertex rounding.

Parameters
size<decimal-list-2 | decimal> A list [x, y] of decimals or a single decimal for (x=y).
o<point-2d> The origin offset coordinate [x, y].
vr<decimal-list-4 | decimal> The vertices rounding radius.
vrm<integer-list-4 | integer> The vertices rounding mode.
vfn<integer-list-4> The vertices arc fragment number.
center<boolean> Center about origin.

Each vertex may be assigned an individual rounding radius, rounding mode, and facet number as described in polygon_round_eve_all_p by using the parameters: vr, vrm, and vfn. When vr is undefined, no rounding is performed on the polygon vertices.

Object example

pg_rhombus( size=[30, 15], vr=[3,1,3,1], center=true );
module pg_rhombus(size=1, o, vr, vrm=1, vfn, center=false)
A polygon rhombus with vertex rounding.
Definition: polygon.scad:824
pg_rhombus

Definition at line 823 of file polygon.scad.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pg_ngon()

module pg_ngon ( = 5,
= 1,
,
vr  ,
vrm  = 1,
vfn  ,
center  = true 
)

A n-sided regular polygon with vertex rounding.

Parameters
n<integer> The number of sides.
r<decimal> The radius.
o<point-2d> The origin offset coordinate [x, y].
vr<decimal-list-n | decimal> The vertices rounding radius.
vrm<integer-list-n | integer> The vertices rounding mode.
vfn<integer-list-n | integer> The vertices arc fragment number.
center<boolean> Center about origin.

Each vertex may be assigned an individual rounding radius, rounding mode, and facet number as described in polygon_round_eve_all_p by using the parameters: vr, vrm, and vfn. When vr is undefined, no rounding is performed on the polygon vertices.

Object example

pg_ngon( n=6, r=10, vr=1, center=true );
module pg_ngon(n=5, r=1, o, vr, vrm=1, vfn, center=true)
A n-sided regular polygon with vertex rounding.
Definition: polygon.scad:874
pg_ngon

Definition at line 873 of file polygon.scad.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pg_triangle_ppp()

module pg_triangle_ppp ( ,
,
vr  ,
vrm  = 1,
vfn  ,
cm  = 0 
)

A polygon triangle specified by three coordinate points with vertex rounding.

Parameters
c<points-list-3> A list, [v1, v2, v3], the vertex coordinates in 2d.
o<point-2d> The origin offset coordinate [x, y].
vr<decimal-list-3 | decimal> The vertices rounding radius.
vrm<integer-list-3 | integer> The vertices rounding mode.
vfn<integer-list-3 | integer> The vertices arc fragment number.
cm<integer> The center mode; [0,1,2, or 3].
cm value description
0 origin at vertex v1
1 origin at triangle centroid
2 origin at triangle incenter
3 origin at triangle circumcenter

Each vertex may be assigned an individual rounding radius, rounding mode, and facet number as described in polygon_round_eve_all_p by using the parameters: vr, vrm, and vfn. When vr is undefined, no rounding is performed on the polygon vertices.

Parameter location

ppp

Object example

pg_triangle_ppp( c=[[-15,-5],[10,15], [10,-10]], vr=1 );
module pg_triangle_ppp(c, o, vr, vrm=1, vfn, cm=0)
A polygon triangle specified by three coordinate points with vertex rounding.
Definition: polygon.scad:975
pg_triangle_ppp

Definition at line 974 of file polygon.scad.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pg_triangle_sss()

module pg_triangle_sss ( ,
= x_axis_ci,
,
vr  ,
vrm  = 1,
vfn  ,
cm  = 0 
)

A polygon triangle specified by three side lengths with vertex rounding.

Parameters
v<decimal-list-3> A list, [s1, s2, s3], the side lengths.
a<integer> The triangle side alignment axis index < x_axis_ci | y_axis_ci >.
o<point-2d> The origin offset coordinate [x, y].
vr<decimal-list-3 | decimal> The vertices rounding radius.
vrm<integer-list-3 | integer> The vertices rounding mode.
vfn<integer-list-3 | integer> The vertices arc fragment number.
cm<integer> The center mode; [0,1,2, or 3].
cm value description
0 origin at vertex v1
1 origin at triangle centroid
2 origin at triangle incenter
3 origin at triangle circumcenter

Each vertex may be assigned an individual rounding radius, rounding mode, and facet number as described in polygon_round_eve_all_p by using the parameters: vr, vrm, and vfn. When vr is undefined, no rounding is performed on the polygon vertices.

Parameter location

sss

Object example

pg_triangle_sss( v=[10,20,25], vr=1, cm=1);
module pg_triangle_sss(v, a=x_axis_ci, o, vr, vrm=1, vfn, cm=0)
A polygon triangle specified by three side lengths with vertex rounding.
Definition: polygon.scad:1047
pg_triangle_sss

Definition at line 1046 of file polygon.scad.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pg_triangle_sas()

module pg_triangle_sas ( ,
= x_axis_ci,
,
vr  ,
vrm  = 1,
vfn  ,
cm  = 0 
)

A polygon triangle specified by size-angle-size with vertex rounding.

Parameters
v<decimal-list-3> A list, [s1, a3, s2], the side lengths and the included angle.
a<integer> The triangle side alignment axis index < x_axis_ci | y_axis_ci >.
o<point-2d> The origin offset coordinate [x, y].
vr<decimal-list-3 | decimal> The vertices rounding radius.
vrm<integer-list-3 | integer> The vertices rounding mode.
vfn<integer-list-3 | integer> The vertices arc fragment number.
cm<integer> The center mode; [0,1,2, or 3].
cm value description
0 origin at vertex v1
1 origin at triangle centroid
2 origin at triangle incenter
3 origin at triangle circumcenter

Each vertex may be assigned an individual rounding radius, rounding mode, and facet number as described in polygon_round_eve_all_p by using the parameters: vr, vrm, and vfn. When vr is undefined, no rounding is performed on the polygon vertices.

Parameter location

sas

Object example

pg_triangle_sas( v=[15,30,20], vr=1, cm=1);
module pg_triangle_sas(v, a=x_axis_ci, o, vr, vrm=1, vfn, cm=0)
A polygon triangle specified by size-angle-size with vertex rounding.
Definition: polygon.scad:1112
pg_triangle_sas

Definition at line 1111 of file polygon.scad.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pg_triangle_asa()

module pg_triangle_asa ( ,
= x_axis_ci,
,
vr  ,
vrm  = 1,
vfn  ,
cm  = 0 
)

A polygon triangle specified by angle-size-angle with vertex rounding.

Parameters
v<decimal-list-3> A list, [a1, s3, a2], the side length and two adjacent angles.
a<integer> The triangle side alignment axis index < x_axis_ci | y_axis_ci >.
o<point-2d> The origin offset coordinate [x, y].
vr<decimal-list-3 | decimal> The vertices rounding radius.
vrm<integer-list-3 | integer> The vertices rounding mode.
vfn<integer-list-3 | integer> The vertices arc fragment number.
cm<integer> The center mode; [0,1,2, or 3].
cm value description
0 origin at vertex v1
1 origin at triangle centroid
2 origin at triangle incenter
3 origin at triangle circumcenter

Each vertex may be assigned an individual rounding radius, rounding mode, and facet number as described in polygon_round_eve_all_p by using the parameters: vr, vrm, and vfn. When vr is undefined, no rounding is performed on the polygon vertices.

Parameter location

asa

Object example

pg_triangle_asa( v=[60,30,25], vr=1, cm=1);
module pg_triangle_asa(v, a=x_axis_ci, o, vr, vrm=1, vfn, cm=0)
A polygon triangle specified by angle-size-angle with vertex rounding.
Definition: polygon.scad:1177
pg_triangle_asa

Definition at line 1176 of file polygon.scad.

+ Here is the call graph for this function:

◆ pg_triangle_aas()

module pg_triangle_aas ( ,
= x_axis_ci,
,
vr  ,
vrm  = 1,
vfn  ,
cm  = 0 
)

A polygon triangle specified by angle-angle-size with vertex rounding.

Parameters
v<decimal-list-3> A list, [a1, a2, s1], a side length, one adjacent and the opposite angle.
a<integer> The triangle side alignment axis index < x_axis_ci | y_axis_ci >.
o<point-2d> The origin offset coordinate [x, y].
vr<decimal-list-3 | decimal> The vertices rounding radius.
vrm<integer-list-3 | integer> The vertices rounding mode.
vfn<integer-list-3 | integer> The vertices arc fragment number.
cm<integer> The center mode; [0,1,2, or 3].
cm value description
0 origin at vertex v1
1 origin at triangle centroid
2 origin at triangle incenter
3 origin at triangle circumcenter

Each vertex may be assigned an individual rounding radius, rounding mode, and facet number as described in polygon_round_eve_all_p by using the parameters: vr, vrm, and vfn. When vr is undefined, no rounding is performed on the polygon vertices.

Parameter location

aas

Object example

pg_triangle_aas( v=[30,40,25], vr=1, cm=1);
module pg_triangle_aas(v, a=x_axis_ci, o, vr, vrm=1, vfn, cm=0)
A polygon triangle specified by angle-angle-size with vertex rounding.
Definition: polygon.scad:1242
pg_triangle_aas

Definition at line 1241 of file polygon.scad.

+ Here is the call graph for this function: