From 83f30a3d8ddf11fd0a817b48b18f902be7bcabbe Mon Sep 17 00:00:00 2001 From: acereca Date: Tue, 9 Feb 2021 10:42:37 +0100 Subject: [PATCH] add `grid` and `round_box` --- .gitignore | 2 ++ LICENSE | 21 +++++++++++++++++++++ README.md | 8 ++++++++ requirements.txt | 2 ++ setup.py | 16 ++++++++++++++++ solidLib/__init__.py | 1 + solidLib/assortment.py | 38 ++++++++++++++++++++++++++++++++++++++ solidLib/globals.py | 1 + solidLib/primitives.py | 10 ++++++++++ 9 files changed, 99 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 requirements.txt create mode 100644 setup.py create mode 100644 solidLib/__init__.py create mode 100644 solidLib/assortment.py create mode 100644 solidLib/globals.py create mode 100644 solidLib/primitives.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..425878a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__/ +solidLib.egg-info/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fb55d20 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Patrick Nisble (@acereca) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 8276fa5..59f023e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ # solidLib A Collection of solidpython functions, helpers etc + +## Content + +- `solidLib.primitives` + - `round_box(x: float, y: float, z: float, r: float)` + +- `solidLib.assortment` + - `grid(x: float, y: float, w: float = 3, h: float = 1.5, fillet: bool = False, dim: float = 59)` diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..bac02b2 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +numpy>=1.19 +solidpython>=1.0 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..b0cd69a --- /dev/null +++ b/setup.py @@ -0,0 +1,16 @@ +#! /usr/bin/env python3 + +from distutils.core import setup + +setup( + name="solidLib", + description="Collection of solidpython tools.", + author="Patrick Nisble", + author_email="acereca@outlook.de", + url="https://git.acereca.net/acereca/solidLib", + version="0.0.1", + install_requires=[ + 'numpy>=1.19', + 'solidpython>=1.0' + ] +) diff --git a/solidLib/__init__.py b/solidLib/__init__.py new file mode 100644 index 0000000..18e515f --- /dev/null +++ b/solidLib/__init__.py @@ -0,0 +1 @@ +from .globals import SEGMENTS diff --git a/solidLib/assortment.py b/solidLib/assortment.py new file mode 100644 index 0000000..4726df9 --- /dev/null +++ b/solidLib/assortment.py @@ -0,0 +1,38 @@ +import solid as scad +from .globals import * + + +def grid( + x: float, + y: float, + w: float = 3, + h: float = 1.5, + fillet: bool = False, + dim: float = 59, +): + + if w > h * 2: + out = scad.polygon([[0, 0], [w / 2, 0], [w / 2 - h, h], [0, h]]) + else: + out = scad.polygon([[0, 0], [w / 2, 0], [0, h]]) + out = scad.linear_extrude(dim)(out) + out = scad.rotate([90, 0, 90])(out) + + if fillet: + scallop = scad.cube([dim - 2 * h - (w - 2 * h), 0.0001, 0.0001]) + scallop = scad.minkowski()(scallop, scad.sphere(r=h, segments=SEGMENTS)) + scallop += scad.rotate([0, -90, 0])(scallop) + scad.translate([dim - w, 0, 0])( + scad.rotate([0, -90, 0])(scallop) + ) + scallop = scad.translate([w / 2, w / 2, h])(scallop) + out -= scallop + + out += scad.translate([0, dim, 0])(scad.rotate([0, 0, -90])(out)) + out += scad.translate([dim, dim, 0])(scad.rotate([0, 0, 180])(out)) + + result = out + for dx in range(x): + for dy in range(y): + result += scad.translate([dim * dx, dim * dy, 0])(out) + + return result diff --git a/solidLib/globals.py b/solidLib/globals.py new file mode 100644 index 0000000..394983f --- /dev/null +++ b/solidLib/globals.py @@ -0,0 +1 @@ +SEGMENTS = 36 diff --git a/solidLib/primitives.py b/solidLib/primitives.py new file mode 100644 index 0000000..84ef55b --- /dev/null +++ b/solidLib/primitives.py @@ -0,0 +1,10 @@ +import solid as s +import numpy as np +from .globals import * + + +def round_box(x, y, z, r): + box = s.cube(np.array([x, y, z]) - r * 2) + wall = s.sphere(r=r, segments=SEGMENTS) + + return s.translate([r, r, r])(s.minkowski()(box, wall))