Skip to content

Instantly share code, notes, and snippets.

@thehans
Created September 23, 2018 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thehans/0e9daa23dc10c1dfa11cb0575839cafc to your computer and use it in GitHub Desktop.
Save thehans/0e9daa23dc10c1dfa11cb0575839cafc to your computer and use it in GitHub Desktop.
pistol grip profile
//use <polyround.scad> // https://github.com/Irev-Dev/Round-Anything/blob/master/polyround.scad
$fs = 0.2;
$fa = 0.2;
total_h = 90;
fingers = 4;
d2 = 3;
d1 = (total_h - (fingers+1)*d2) / fingers;
r1 = d1/2;
r2 = d2/2;
//r1 = 10;
dx = r1+r2;
y0 = -r2;
x0 = r1;
ratio = 0.5;
shape = [
[0,0,0],
[0,total_h,0],
[x0+ratio*r1, 8*r1+9*r2,r2],
[x0+r1, 7*r1+8*r2,-r1],
[x0+ratio*r1, 6*r1+7*r2,r2],
[x0+r1, 5*r1+6*r2,-r1],
[x0+ratio*r1, 4*r1+5*r2,r2],
[x0+r1, 3*r1+4*r2,-r1],
[x0+ratio*r1, 2*r1+3*r2,r2],
[x0+r1, 1*r1+2*r2,-r1],
[x0+ratio*r1, 0*r1+1*r2,r2],
];
//scale() rotate_extrude(angle=180)
finger_profile(shape);
//diameter_labels(shape);
module finger_profile(shape) {
rounded_polygon(shape);
//polygon(polyRound(shape));
}
module diameter_labels(shape, base_index=1) {
c = "center";
l = len(shape)-1;
for(i=[0:l]) let(p = shape[i]) color([1,0,0])
translate([p.x,p.y]) {
text(text=str(i+base_index), size=abs(p[2]), halign=c, valign=c);
circle(r=p.z < 0 ? -p.z : p.z);
}
}
module rounded_polygon(points)
difference() {
len = len(points);
union() {
for(i = [0 : len - 1])
if(points[i][2] > 0)
translate([points[i].x, points[i].y])
circle(points[i][2]);
polygon([for(i = [0 : len - 1])
let(ends = tangent(points[i], points[(i + 1) % len]))
for(end = [0, 1])
ends[end]]);
}
for(i = [0 : len - 1])
if(points[i][2] < 0)
translate([points[i].x, points[i].y])
circle(-points[i][2]);
}
function tangent(p1, p2) =
let(
r1 = p1[2],
r2 = p2[2],
dx = p2.x - p1.x,
dy = p2.y - p1.y,
d = sqrt(dx * dx + dy * dy),
theta = atan2(dy, dx) + acos((r1 - r2) / d),
xa = p1.x +(cos(theta) * r1),
ya = p1.y +(sin(theta) * r1),
xb = p2.x +(cos(theta) * r2),
yb = p2.y +(sin(theta) * r2)
)[ [xa, ya], [xb, yb] ];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment