Skip to content
sadr0b0tPublic

About

Generate 2D shapes as arrays of points in OpenSCAD

Resources

Stars

5 stars

Watchers

1 watching

Forks

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

2d_points

Generate 2D shapes as arrays of points in OpenSCAD
thingiverse: https://www.thingiverse.com/thing:2930492

Also available from Openscad-Modules repo https://github.com/RobertFach/Openscad-Modules

spm install 2d_points

All shapes are generated as array of points, you should apply them to polygon call on your own. This might be convenient, if you want to pass some unknown beforehand shape to module or function as param.

use <2d_points/2d_points.scad>

Draw arcs and circles

    polygon(circle_points(r=3));
    translate([10, 0]) polygon(circle_points(r=3, a1=45, a2=270));
    translate([20, 0]) polygon(circle_points(r=3, fn=8));
    translate([30, 0]) polygon(circle_points(r=3, a1=45, a2=270, fn=8));

Draw rounded rect

    polygon(rect_points([10, 15], center=true));
    translate([15, 0]) polygon(rect_points([10, 15]));
    translate([30, 0]) polygon(rect_points([10, 15], r=4));
    translate([45, 0]) polygon(rect_points([10, 15], r=4, r3=0, r4=2));

Draw Bezier curves of any degrees (credit to Christian Limberg: Bezier curve drawing code taken from this post with some fixes, additions and refactoring http://climberg.de/page/openscad-implementation-of-bezier-curves-of-any-degrees/)

    seg1=[[0,0], [0, 10], [10, 10], [10, 0]];
    seg2=[[0,0], [-5, 10], [15, 10], [10, 0]];
    seg3=[[0,0], [-5, 5], [15, 15], [10, 0]];
    seg4=[[0,0], [0, 10], [5, 15], [10, 10], [10, 0]];
    
    color([0.9,0.4,0.9]) polygon(seg1);
    linear_extrude(height=2) polygon(bezier_points(seg1));
    
    translate([15, 0, 0]) {
        color([0.9,0.4,0.9]) polygon(seg1);
        linear_extrude(height=2) polygon(bezier_points(seg1, fn=5));
    }
    
    translate([35, 0, 0]) {
        color([0.9,0.4,0.9]) polygon(seg2);
        linear_extrude(height=2) polygon(bezier_points(seg2));
    }
    
    translate([60, 0, 0]) {
        color([0.9,0.4,0.9]) polygon(seg3);
        linear_extrude(height=2) polygon(bezier_points(seg3));
    }
    
    translate([80, 0, 0]) {
        color([0.9,0.4,0.9]) polygon(seg4);
        linear_extrude(height=2) polygon(bezier_points(seg4));
    }

And compound Bezier curves (polybezier). Each segment can be of any degree.

    segments=[
        [[0, 0], [0, 10], [10, 10], [10, 0]],
        [[10, 0], [5, -10], [20, -5], [20, 0]],
        [[20, 0], [15, 10], [35, 10], [30, 0]],
        [[30, 0], [20, -10], [35, -15], [45, -10], [40, 0]]
    ];
    
    color([0.4,0.9,0.9]) polygon(segments[0]);
    color([0.9,0.4,0.9]) polygon(segments[1]);
    color([0.9,0.9,0.4]) polygon(segments[2]);
    color([0.4,0.4,0.9]) polygon(segments[3]);
    linear_extrude(height=2)
        polygon(polybezier_points(segments, fn=100));

also: array of segment points for polybezier_points is also compatible with array generated by "SVG to OpenSCAD Bezier - InkScape extension" https://www.thingiverse.com/thing:2805184 (by Gael Lafond): simply copy array of points from generated scad file and paste to polybezier_points call's first paramter.

About

Generate 2D shapes as arrays of points in OpenSCAD

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages