Skip to content

Instantly share code, notes, and snippets.

@ridercz
Created April 4, 2020 19:56
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 ridercz/d403dfe63ca1fbc37a08617bdc7583ba to your computer and use it in GitHub Desktop.
Save ridercz/d403dfe63ca1fbc37a08617bdc7583ba to your computer and use it in GitHub Desktop.
MagClasp - SCAD
/*****************************************************************************
* PARAMETRIC MAGNETIC CLASP for protective mask version 1.1.0 (2020-03-30) *
* ------------------------------------------------------------------------- *
* Copyright (c) Michal Altair Valasek, 2020 - Licensed under CC BY-NC-SA *
* www.rider.cz * www.altairis.cz * www.altair.blog *
*****************************************************************************/
include <A2D.scad>; // https://github.com/ridercz/A2D
assert(a2d_required([1, 5, 0]), "Please upgrade A2D library to version 1.5.0 or higher.");
/* [General] */
// Render two parts clasped together
render_preview = false;
// Add holding peg and corresponding hole
use_peg = true;
/* [Ribbon] */
// Width of ribbon tape
ribbon_width = 20; // [20:50]
// Thickness of ribbon (width of hole)
ribbon_thickness = 3; // [2:10]
// Number of holes
ribbon_holes = 2; // [1, 2, 3]
/* [Magnet] */
// Diameter of magnet hole
magnet_diameter = 11;
// Height of magnet hole
magnet_height = 1.8;
// Amount of material under and over magnet, should be 2-4 layers
magnet_cover = .4;
/* [Other] */
// Minimal wall thickness, should be 4 perimeters
wall_thickness = 1.67;
// Radius of rounded corners
corner_radius = 3;
// Clearance of pegs
part_clearance = 1;
/* [Hidden] */
$fudge = 1;
total_width = ribbon_width + 2 * wall_thickness;
module_length = ribbon_width / 2 + (wall_thickness + ribbon_thickness) * (ribbon_holes + 1);
module_height = magnet_height + 2 * magnet_cover;
polygon_sides = 6;
polygon_angle = 180 / polygon_sides;
// Main render
if(render_preview) {
// Render two parts together, to show how it works and also check if it fits
color("#cc0000") part();
color("#000099") translate([0, 0, module_height * 2 + part_clearance / 2]) rotate([0, 180, 0]) part();
} else {
// Render single part, for export and printing
part();
}
// Part
module part() {
difference() {
// Extruded base 2D shape
linear_extrude(module_height * 2) difference() {
// Main shape
hull() {
r_regpoly(od = total_width, vertices = polygon_sides, radius = corner_radius, $fn = 16);
translate([-module_length, -total_width / 2]) r_square([corner_radius * 2, total_width], corner_radius, $fn = 16);
}
// Ribbon holes
hole_xpos = [ for(i = [0:ribbon_holes - 1]) -module_length + wall_thickness * (i + 1) + ribbon_thickness * i ];
for(x = hole_xpos) translate([x, -ribbon_width / 2]) r_square([ribbon_thickness, ribbon_width], ribbon_thickness / 2, $fn = 16);
// Peg hole
if(use_peg) translate([-corner_radius / 2, 0]) hull()
for(a = [-180 + polygon_angle, +180 - polygon_angle]) translate(vector_point(alpha = a, delta = total_width / 2 - corner_radius))
circle(d = corner_radius + part_clearance, $fn = 16);
}
// Other half cutout
translate([0, 0, module_height]) linear_extrude(module_height + $fudge) r_regpoly(od = total_width + part_clearance, vertices = polygon_sides, radius = corner_radius, $fn = 16);
// Magnet hole
translate([0, 0, magnet_cover]) cylinder(d = magnet_diameter, h = magnet_height, $fn = 32);
}
// Peg
if(use_peg) translate([corner_radius / 2, 0]) hull()
for(a = [-polygon_angle, +polygon_angle]) translate(vector_point(alpha = a, delta = total_width / 2 - corner_radius))
cylinder(d = corner_radius, h = module_height * 2, $fn = 16);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment