Hey! This thing is still a Work in Progress. Files, instructions, and other stuff might change!

2D Graphing Library

2067
Downloads
535
Views
Published on September 10, 2011

Description

This is an openscad library to create 2d representations of equations (cartesian, polar, or parametric). You can export the graph to dxf or extrude it directly to make interesting objects like an ellipsoid. It's incredibly ineffecient and slow (can't really be helped, it is due to openscad limitations) and a little buggy still (probably my fault), but it mostly works. Enjoy!

NOTE: Without this[1] bug fix, this library functions VERY poorly (openscad crashes a lot) so I suggest getting the latest openscad source and compiling that if you want to try this library.

Maybe if I can wrap my head around polyhedrons in openscad I will extend this to 3d functions. :)

[1] github.com/openscad/openscad/commit/f0bd1eed9746e0349700c969292c9eeca58 c5635

Instructions



function f(x) = ... // for a cartesian equation
function r(theta) = ... // for a polar equation
function x(t) = ... // and
function y(t) = ... // for a parametric equation

//then
// param (optional) [lower bound, upper bound]
// param (optional) thickness of the line, without thickness it would be 1d!
// param (optional) number of polygons to draw (resolution)
// param (optional) polar=true or parametric=true, defaults to cartesian
2dgraph([-10, 10], 2, $fn=100);
Report as inappropriate

You must be logged in to post a comment.

Thanks for making this - I just used it for a picture frame project that includes Lissajous Curves.

http://www.thingiverse.com/thi...

Some comments on your code itself:

If you use the '//' method of commenting, instead of the '/*' style, it's easier to uncomment the individual functions by simply doing Ctl-D/Shift-Ctl-D

You might want to introduce 'steps' instead of using $fn to represent the number of steps. $fn will have other side effects that you probably are not intending, particularly with surfaces of revolution. For example:

module 2dgraph(bounds = [-10,10], th=2, polar=false, parametric=false, steps=24
)
{
// and if you must
$fn=24;
.
.
.
}

But, I would not even use the $fn=24 inside the module. As it is a global thing, you can always apply it from the outside.

I really like the simplicity and modularity. If we had 'function pointers', it would be even more modular.

Thanks for the tips, I have made your suggested changes. I didn't know that shortcut, that's a good one!

Yes, function pointers would have been great and real variables would help a great deal with efficiency.

I really like this!

If you want to go for 3D, you might take a look at this library: http://www.thingiverse.com/thi... for solids of revolution

or this one: http://www.thingiverse.com/thi...
which deals with mesh surfaces in general.

There are two things you have to deal with for polyhedra. 1) surface normals. You must know these so you can calculate a thickness. 2) boundaries. You must know these so you can create closed polyhed
ra in bits and pieces.