SVG Shapes

SVG paths can be used to create wires or faces. Using extrude or other operations like revolve, pipe, etc, you can build a rich variety of features pretty quickly. You can utilize any SVG editor, one example being, SVG-Edit to design these shapes.
svgPath2Face()

Creates a shape solid using value of the path element of an SVG.

Syntax

cadlib.svgPath2Face(svgPath, scale);

Parameters

Name Type Description
svgPath string value of sVG path element
scale object An object with { x, y} values

var scale = {x:0.1, y:0.1};

Returns

Face

Example

//Main function which returns the solid
function build() {

    //lightning
    var path=var path = "M 0 100 L 40 60 L 60 80 L 100 0 L 60 40 L 40 20 L 0 100 Z";

    //Returns the shape
    return extrudeFace(path, 2.0);
}

//Used to extrude a path
function extrudeFace(path, height) {

    //specify scale
    var scale = {x:0.1, y:0.1};

    //generate face
    var face = cadlib.svgPath2Face(path, scale);

    //Axis of extrusion is y axis.
    var dir = {x:0, y:height, z:0};

    //extrude
    var solid = cadlib.extrude(face,dir);

    return solid;
}

parseSVGPath()

Creates a Face from specified edges

Syntax

cadlib.face(edges);

Parameters

Name Type Description
edges Array Array of Edge objects

Returns

Face


edgesFromSVG()

Creates edges from SVG Path. Path need not be closed.

Syntax

cadlib.edgesFromSVG(path, scale);

Parameters

Name Type Description
path string Value of SVG path element
scale object {x, y} Scales the path by specified factor

Returns

Wire




Additional Path Examples

Few more examples of SVG paths for quick reference. You can copy-n-paste it into above code to see the results.

Hexagone

var path = "M 100 43.3012702 L 75 0 L 25 0 L 0 43.3012702 L 25 86.6025404 L 75 86.6025404 L 100 43.3012702 Z";

Rectangle with a rounded top

var path = "M 0 100 L 50 100 L 50 25 A 25 25 0 0 0 25 0 A 25 25 0 0 0 0 25 L 0 100 Z";

Rounder rectangle

var path = "M 0 89 A 11 11 0 0 0 11 100 L 39 100 A 11 11 0 0 0 50 89 L 50 11 A 11 11 0 0 0 39 0 L 11 0 A 11 11 0 0 0 0 11 L 0 89 Z";

Heart

var path = "M 31.2132034 17.0710678 A 10 10 0 0 0 17.0710678 2.9289322 A 10 10 0 0 0 2.9289322 17.0710678 L 17.0710678 31.2132034 L 31.2132034 17.0710678 Z";

Polygon 10 sided

var path = "M 33.5814036 14.1313159 L 28.8115171 4.7698865 L 19.4500877 0 L 9.0728633 1.6435909 L 1.6435909 9.0728633 L 0 19.4500877 L 4.7698865 28.8115171 L 14.1313159 33.5814036 L 24.5085403 31.9378127 L 31.9378127 24.5085403 L 33.5814036 14.1313159 Z";

Half band clamp

var path = "M 27.4429874 10.8634469 A 12.7 12.7 0 0 0 3.0120876 15.1460338 A 12.7 12.7 0 0 0 3.0120876 16.2539662 A 12.7 12.7 0 0 0 27.4429874 20.5365531 A 2 2 0 0 1 29.3795156 19.3001186 L 41.1853211 19.8155712 A 0.7 0.7 0 0 1 41.8541213 20.5454385 L 41.5662334 27.1391568 A 0.7 0.7 0 0 1 40.836366 27.807957 L 27.2208312 27.2134899 A 2 2 0 0 0 25.841661 27.6848534 A 15.7 15.7 0 0 1 0.0149429 16.3848244 A 15.7 15.7 0 0 1 0.0149429 15.0151756 A 15.7 15.7 0 0 1 25.841661 3.7151466 A 2 2 0 0 0 27.2208312 4.1865101 L 40.836366 3.592043 A 0.7 0.7 0 0 1 41.5662334 4.2608432 L 41.8541213 10.8545615 A 0.7 0.7 0 0 1 41.1853211 11.5844288 L 29.3795156 12.0998814 A 2 2 0 0 1 27.4429874 10.8634469 Z";

Rectangle with bubble corners

var path = "M 1.4644661 94.3933983 L 1.4644661 8.5355339 A 5 5 0 0 1 8.5355339 1.4644661 L 44.3933983 1.4644661 A 5 5 0 0 1 51.4644661 8.5355339 L 51.4644661 94.3933983 A 5 5 0 0 1 44.3933983 101.4644661 L 8.5355339 101.4644661 A 5 5 0 0 1 1.4644661 94.3933983 Z";

Star with 8 sides

var path = "M 100 50 L 63.858193 44.2597485 L 85.3553391 14.6446609 L 55.7402515 36.141807 L 50 0 L 44.2597485 36.141807 L 14.6446609 14.6446609 L 36.141807 44.2597485 L 0 50 L 36.141807 55.7402515 L 14.6446609 85.3553391 L 44.2597485 63.858193 L 50 100 L 55.7402515 63.858193 L 85.3553391 85.3553391 L 63.858193 55.7402515 L 100 50 Z" ;

Letter T

var path = "M 39.4453125 0 L 39.4453125 5.765625 L 23.9765625 5.765625 L 23.9765625 51.8203125 L 15.46875 51.8203125 L 15.46875 5.765625 L 0 5.765625 L 0 0 L 39.4453125 0 Z";

Hand drawn irregular shape

var path = "M 80.0000314 50.0667088 C 80.0000314 13.6149223 70.6573793 0.0007297 58.3575069 0.0007297 C 52.6611916 0.0007297 46.3306115 2.920702 40.0000314 7.8444865 C 26.1538776 18.6137173 12.3077237 38.9687469 5.0978921 59.3237765 C 1.8935225 68.3704563 0.0000314 77.4171361 0.0000314 85.6222643 C 0.0000314 104.319448 9.8321005 118.6468232 36.3899387 118.6468232 C 47.7099451 118.6468232 62.0686947 116.043821 80.0000314 110.0667088";

Bunny

var path = "m248.92621,321.72055c-6.03008,-2.71928 1.83871,-8.15604 4.81778,-10.56101c2.00666,-1.85214 -11.5003,0.25981 -5.79778,-6.1697c6.25649,-5.25256 3.89312,-14.13874 -2.36067,-18.26936c-8.60652,-5.81122 -19.64923,-10.78482 -22.82879,-21.63595c-3.21501,-6.75869 4.40944,-13.87697 -0.49456,-19.98024c-3.94728,-7.92446 0.66427,-16.188 3.53068,-23.52878c1.31819,-10.15447 -6.75681,-18.18473 -11.19756,-26.5272c-5.49866,-7.97225 -8.66834,-17.26175 -9.12382,-26.94251c-1.19581,-4.13216 0.12755,-10.54929 4.90266,-4.97831c9.99979,8.00711 20.97788,15.60489 27.97656,26.56469c1.32478,3.95877 6.62944,15.43241 6.92565,5.04237c0.13873,-14.28038 4.50029,-29.85527 15.67645,-39.42494c7.60183,-6.92676 11.70146,5.20172 12.05616,11.36495c1.97861,12.12665 -1.30118,24.15221 -4.95601,35.60748c-1.34173,5.32363 -4.83592,19.91233 5.12957,14.53323c22.95691,-8.86318 50.7709,0.44554 65.72405,19.48553c6.87383,9.21893 9.88412,21.0631 9.81616,32.43551c-3.53949,6.68124 9.61159,-0.12516 4.84628,7.58297c-2.80529,8.53877 -10.73133,13.17201 -16.28329,19.61703c-5.64958,5.16448 -1.45776,16.20636 -10.80052,17.83337c-13.63222,4.20248 -27.94718,6.04331 -42.1388,7.11481c-7.94159,1.62701 -11.79568,-7.45398 -4.18395,-11.22918c3.64927,-5.62565 14.08974,-6.01989 17.19181,-6.91109c-7.41293,0.72531 -16.55492,-2.30032 -22.80141,2.29063c-3.78295,6.14114 -6.81276,14.22422 -14.74565,15.97709c-3.56502,0.99013 -7.2305,1.78414 -10.88098,0.70861l-0.00001,0.00001z"