Skip to content

Instantly share code, notes, and snippets.

Avatar

Hans Loeblich thehans

View GitHub Profile
@thehans
thehans / ProjectEnclosure.py
Created Nov 13, 2011
FreeCAD script for generating parametric project enclosures
View ProjectEnclosure.py
from __future__ import division # allows floating point division from integers
from FreeCAD import Base
import Part
import math
# Run this macro to create a generic project enclosure box
# You can change all the parameters by selecting the object in the tree view and tweaking values in the "Data" tab
# Possible additions/improvements
# counterbore bridging .4mm
@thehans
thehans / Extrusions.py
Created Nov 26, 2011
Parametric Aluminum Extrusion Module
View Extrusions.py
from math import sqrt
from FreeCAD import Base
#Main class for general extrusion related methods
class ExtrusionProfile():
def __init__(self, profile):
self.profile = profile
def makeExtrusion(self, p1, p2, rotateAngle=0):
"""Generates an extrusion which connects between two points,
@thehans
thehans / MeasureCircle.py
Created Nov 30, 2011
A FreeCAD script for the purpose of inspecting the radius and center of circles in 3D models
View MeasureCircle.py
from FreeCAD import Base
class MeasureCircle:
"""This class will report the computed radius and center of a circle or arc given 3 vertices.
A line is drawn from the first vertex to the center of the circle, which may be used for future measurements.
Just select the vertices and the result will be shown in Report View
Edges may also be selected and count as two vertices.
If two edges are selected one of the vertices in the second edge is not used in the calculation"""
def __init__(self):
self.points = []
@thehans
thehans / Protractor.py
Created Dec 1, 2011
Protractor script for FreeCAD, measures angle between two edges
View Protractor.py
from FreeCAD import Base
import math
class Protractor:
"""Reports the angle between two edges.
Select the edges and the result will be shown in Report View"""
def __init__(self):
self.firstEdge = None
Gui.Selection.addObserver(self)
FreeCAD.Console.PrintMessage("Select any 2 edges\n")
@thehans
thehans / EasyPart.py
Created Feb 11, 2012
Helper functions for improving FreeCAD's Python API
View EasyPart.py
import math as _math
from math import ceil, exp, floor, log as ln, log10 as log, pow, sqrt
from FreeCAD import Base
import Part
# Trigonometric wrappers
def acos(x):
"""Return the arc cosine of x, in degrees."""
return _math.degrees(_math.acos(x))
View gist:c30c259e83da4e89ccbd975a511dab68
// shear such that point will translate by [p.x,p.y] as z-axis is traversed by p.z units
module shearAlongZ(p) {
multmatrix([
[1,0,p.x/p.z,0],
[0,1,p.y/p.z,0],
[0,0,1,0]
]) children();
}
rotate([0,0,0])
@thehans
thehans / drawPath.scad
Created Mar 14, 2017
Userspace functions to replicate basic 2d modules as functions over point vectors, plus path drawing
View drawPath.scad
// enable View->Animate (FPS = 60, Steps = 300, for example),
// to see function behavior at different angles
p0 = [-4,0];
p1 = [4,0];
angle = 360*$t+90;
profile = [p0+polar(3,180+angle), p0, p1, p1+polar(3,-angle)];
$fn=100;
drawPath(profile, 1, false);
@thehans
thehans / alternative_spheres.scad
Last active Nov 28, 2017
Alternative sphere implementations in OpenSCAD userspace
View alternative_spheres.scad
translate([-30,0,0]) poly3d(sphere(r=9,$fn=80));
translate([-10,0,0]) poly3d(normalized_cube(r=9,div_count=20));
translate([10,0,0]) poly3d(spherified_cube(9,div_count=20));
translate([30,0,0]) poly3d(icosahedron(9,n=4));
module poly3d(p) {
polyhedron(points=p[0],faces=p[1]);
}
function normalize(v) = v / norm(v); // convert vector to unit vector
@thehans
thehans / L_system.scad
Last active Jan 12, 2020
L-system implementation in OpenSCAD
View L_system.scad
/* L-system OpenSCAD library by Hans Loeblich
Version 2.0
- Now supports "M" move without draw
- Also support position save "[" and restore "]"
- Core functions have been completely rewritten and are about twice as fast using half the memory from before.
- Rules now take the form of a single string per rule: "X=ABC"
- Added new examples to demonstrate added features
This library is for creating L-systems, aka Lindenmayer System,
View gist:800982fb9cf95ad2721f5dc048f84809
instrs = "-+-+-RF+LFL+FR-F-+LF-RFR-FL+F+LF-RFR-FL+-F-RF+LFL+FR-+F+-+LF-RFR-FL+F+-RF+LFL+FR-F-RF+LFL+FR-+F+LF-RFR-FL+-F-+LF-RFR-FL+F+-RF+LFL+FR-F-RF+LFL+FR-+F+LF-RFR-FL+-+F+-RF+LFL+FR-F-+LF-RFR-FL+F+LF-RFR-FL+-F-RF+LFL+FR-+-F-+-+LF-RFR-FL+F+-RF+LFL+FR-F-RF+LFL+FR-+F+LF-R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