GithubHelp home page GithubHelp logo

kartchnb / openscad-envelope-tools-library Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 1.97 MB

An OpenSCAD library that allows geometry to be scaled to fit a space without distortion

OpenSCAD 100.00%
openscad openscad-library

openscad-envelope-tools-library's Introduction

envelope_tools

One of the great strengths of OpenSCAD is the ability to develop parametric models that can be modified easily using the OpenSCAD customizer. The end user of a well-written model does not need to understand OpenSCAD code to develop their own customized model.

One of the greatest weaknesses of OpenSCAD is that it does not provide a way to query the dimensions of geometry. This means, for instance, that allowing the user to enter arbitrary text to be incorporated into the model can be difficult since there is no way to tell how wide the text will be and to ensure it can be scaled correctly. The designer must determine whether to fit the text to the width of the space, the height of the space, or provide an additional option for the user to select which.

Well, I wasn't satisifed, so I wrote this library to work around this weakness in some situations. It allows 2-dimensional geometry to be scaled to fit a given space without distortion. If it's too wide for the space, it will be scaled to fit the width, otherwise it will fit the height.

For example, this code was used to generate the following image (the red square shows the area being scaled to). Note that the string is scaled to fit the width of the square:

use<envelope_tools/envelope_tools.scad> // Be sure to "use" rather than "include"

Text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
Square_Space = [100, 100];

square_resize(Square_Space)
    text(Text, valign="center", halign="center");

#square(Square_Space, center=true);

image

And, a simple change to the Text string, as shown, will result in the following picture. Note that the letter "I" is scaled to fit the height of the square:

use<envelope_tools/envelope_tools.scad> // Be sure to "use" rather than "include"

Text = "I";
Square_Space = [100, 100];

square_resize(Square_Space)
    text(Text, valign="center", halign="center");

#square(Square_Space, center=true);

image

Additionally, rectangular or circular "envelopes" can be created for any geometry. These "envelopes" will outline the child geometry, matching its width and height. For example, the following code will create a rectangular "envelope" around the text that will be updated if the text is changed

use<../envelope_tools.scad>

Text = "Envelope";

square_envelope()
    text(Text);
#text(Text);

image

Support for 3-dimensional geometry is still a work in progress. It mostly works... mostly. A simple example of using this library for both 2D and 3D geometry can be found in the "test" directory in the file "trophy.scad".

To use, simply install the library into your OpenSCAD library folder.

Note that this library abuses OpenSCAD a bit to achieve this, so you may notice some visual glitches when previewing models in OpenSCAD. So far, everything I've designed with this library has worked just fine when rendered and printed.

Also note that the library should be added to your project with the use<> command rather than include<>, or you will get unwanted test renders in your model. This is because each file contains test code. The upshot is that you can open each library file in OpenSCAD to see a sample of what the functions in that file do.

I'm still working on documenting this library. Right now, it's a bit difficult to understand and use. Hopefully, I'll find time to fix that.

openscad-envelope-tools-library's People

Contributors

kartchnb avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.