Created
October 17, 2023 13:23
-
-
Save aphexddb/f9930e39c4ae6d82109d11ea8d480342 to your computer and use it in GitHub Desktop.
40k wargaming model base SCAD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
base_diameter = 60; | |
base_ellipse_width = 35; // set to 0 to keep as circle | |
base_height = 4.3; | |
base_top_diameter_difference = 4; | |
wall_thickness = 1.5; | |
top_thickness = 1.5; | |
text_size = 4; | |
text_heigth = 1.2; | |
// NOTE: if you are creating an ellipse (oval), use an even number of magnets | |
magnet_count = 4 ; // Set to 0 to remove altogether | |
magnet_diameter = 4; | |
magnet_thickness = 1.5; | |
magnet_well_wall_thickness = 2.5; | |
magnet_tolerance = 0.0; // Use this to compensate for 3d printer inaccuracy | |
model_smoothness = 120; // A higher number means smoother curves but takes longer to render and adds more geometry | |
// Calculated parameters | |
bottom_radius = base_diameter / 2; | |
top_radius = bottom_radius - (base_top_diameter_difference / 2); | |
magnet_distance_from_centre = (top_radius - wall_thickness) * 0.66; | |
// 1. Create the basic base shape by subtracting one cone from another | |
difference() { | |
if (base_ellipse_width > 0) { | |
resize([base_diameter,base_ellipse_width]) cylinder( | |
h = base_height, //height | |
d1 = (base_diameter - base_top_diameter_difference), //top | |
d2 = base_diameter, //bottom | |
$fn = model_smoothness | |
); | |
} else { | |
cylinder( | |
h = base_height, //height | |
d1 = (base_diameter - base_top_diameter_difference), //top | |
d2 = base_diameter, //bottom | |
$fn = model_smoothness | |
); | |
} | |
translate([0, 0, top_thickness]) // shift inner cone up by the top thickness | |
if (base_ellipse_width > 0) { | |
resize([base_diameter,base_ellipse_width]) cylinder( | |
h = base_height + 1, //add 1mm of extra height to ensure a clean subtraction | |
r1 = ((base_diameter - base_top_diameter_difference) / 2) - wall_thickness, //top | |
r2 = bottom_radius - wall_thickness, //bottom | |
$fn = model_smoothness | |
); | |
} else { | |
cylinder( | |
h = base_height + 1, //add 1mm of extra height to ensure a clean subtraction | |
r1 = ((base_diameter - base_top_diameter_difference) / 2) - wall_thickness, //top | |
r2 = bottom_radius - wall_thickness, //bottom | |
$fn = model_smoothness | |
); | |
} | |
} | |
// 2. Add the text to the centre of the base | |
translate([0, 0, top_thickness]) | |
if (base_ellipse_width > 0) { | |
linear_extrude(height = text_heigth) { | |
text( | |
str(base_diameter,"x",base_ellipse_width), | |
font = "Arial:style=Bold", | |
halign = "center", | |
valign = "center", | |
size = text_size, | |
$fn = model_smoothness | |
); | |
}; | |
} else { | |
linear_extrude(height = text_heigth) { | |
text( | |
str(base_diameter), | |
font = "Arial:style=Bold", | |
halign = "center", | |
valign = "center", | |
size = text_size, | |
$fn = model_smoothness | |
); | |
}; | |
} | |
// 3. (optional) Add the magnet holders | |
if(magnet_count > 0) { | |
magnet_angle_increment = 360 / magnet_count; | |
ratio = base_ellipse_width > 0 ? base_ellipse_width / base_diameter : 1; | |
for(a = [1:magnet_count]) { | |
angle = a * magnet_angle_increment; | |
center_dist = (angle > 300 || angle < 60) || (angle < 240 && angle > 120) ? magnet_distance_from_centre * ratio: magnet_distance_from_centre; | |
echo("rotation angle", angle,"distance",center_dist); | |
rotate([0, 0, angle]) | |
translate([0, center_dist, top_thickness]) | |
difference() { | |
cylinder( | |
h = base_height - top_thickness, | |
d = (magnet_diameter + magnet_well_wall_thickness), | |
$fn = model_smoothness | |
); | |
translate([0, 0, base_height - top_thickness - magnet_thickness - magnet_tolerance]) | |
cylinder( | |
top_thickness + magnet_tolerance + 1, //add 1mm of extra height to ensure a clean subtraction | |
d = magnet_diameter + magnet_tolerance, | |
$fn=model_smoothness | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment