Skip to content

Instantly share code, notes, and snippets.

@thehans
thehans / Extrusions.py
Created November 26, 2011 23:23
Parametric Aluminum Extrusion Module
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 November 30, 2011 05:34
A FreeCAD script for the purpose of inspecting the radius and center of circles in 3D models
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 / EasyPart.py
Created February 11, 2012 03:55
Helper functions for improving FreeCAD's Python API
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))
@thehans
thehans / drawPath.scad
Created March 14, 2017 03:58
Userspace functions to replicate basic 2d modules as functions over point vectors, plus path drawing
// 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);
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-RFR-FL+-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+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+-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-+-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-RFR-FL+-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+LF-RFR-FL+-F-RF+LFL+FR-+-F
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@thehans
thehans / gist:e45693b0bdf6077e92a225c2af67397a
Last active July 28, 2017 18:28
Roughly simulating gravitational effects in openscad, by request
use <functional.scad>; // from https://github.com/thehans/FunctionalOpenSCAD
black_hole_center = [5,5,5];
black_hole_mass = 45*$t;
wallsize = [10,10];
stepsize = [0.5,0.5];
grid = gridPoints([wallsize.x,0.1], stepsize);
wall = linear_extrude(height=10, poly=grid, slices=wallsize.y/stepsize.y);
warpedWall = warpPoints(wall, black_hole_center, black_hole_mass);
This file has been truncated, but you can view the full file.
group() {
group() {
group();
}
group() {
group() {
group();
group() {
group() {
module recur(i) {
if (i % 100 == 0) echo(i);
if (i > 0) {
recur(i-1);
}
}
recur(1000);
group() {
group();
group();
group();
group();
group();
group();
group();
group();
group();