Tweaks to thread.

Better thread crest detection.
No longer shrtens thread by eps (to avoid z fight) if all one colour.
Comment about left hand threads.
This commit is contained in:
Chris Palmer 2020-07-14 09:42:32 +01:00
parent 9f4ed2b915
commit bc919529d3
4 changed files with 31 additions and 23 deletions

View File

@ -5546,6 +5546,8 @@ specify a chamfer angle.
Threads are by default solid, so the male version is wrapped around a cylinder and the female inside a tube. This can be suppressed to just get the helix, for
example to make a printed pot with a screw top lid.
A left hand thread can be made by using mirror([0,1]).
Threads with a typical 60 degree angle appear too bright with OpenSCAD's primitive lighting model as they face towards the lights more than the top and sides of
a cylinder. To get around this a colour can be passed to thread that is used to colour the cylinder and then toned down to colour the helix.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 219 KiB

After

Width:  |  Height:  |  Size: 219 KiB

View File

@ -46,7 +46,7 @@ module threads()
color(colour)
translate([80, 0])
thread(dia, pitch, length, profile, starts = 1, top = -1, bot = -1, female = female);
}
}
let($show_threads = true)
threads();

View File

@ -26,6 +26,8 @@
//! Threads are by default solid, so the male version is wrapped around a cylinder and the female inside a tube. This can be suppressed to just get the helix, for
//! example to make a printed pot with a screw top lid.
//!
//! A left hand thread can be made by using mirror([0,1]).
//!
//! Threads with a typical 60 degree angle appear too bright with OpenSCAD's primitive lighting model as they face towards the lights more than the top and sides of
//! a cylinder. To get around this a colour can be passed to thread that is used to colour the cylinder and then toned down to colour the helix.
//!
@ -61,10 +63,12 @@ module thread(dia, pitch, length, profile, center = true, top = -1, bot = -1, st
// Extract some properties from the profile, perhaps they should be stored in it.
//
h = max([for(p = sprofile) p.y]);
maxx = max([for(p = sprofile) p.x]);
minx = min([for(p = sprofile) p.x]);
crest_xmax = max([for(p = sprofile) if(p.x != maxx) p.x]);
crest_xmin = min([for(p = sprofile) if(p.x != minx) p.x]);
xs = [for(p = sprofile) p.x];
maxx = max(xs);
minx = min(xs);
crest_xs = [for(p = sprofile) if(p.y == h) p.x];
crest_xmax = max(crest_xs);
crest_xmin = min(crest_xs);
//
// If the ends don't taper we need an extra half turn past the ends to be cropped horizontally.
//
@ -129,11 +133,13 @@ module thread(dia, pitch, length, profile, center = true, top = -1, bot = -1, st
render() intersection() {
polyhedron(points, ends_faces);
len = length - 2 * eps;
shorten = !is_undef(colour);
len = shorten ? length - 2 * eps : length;
offset = shorten ? eps : 0;
rotate_extrude()
if(female) {
difference() {
translate([0, eps])
translate([0, offset])
square([r + h + overlap, len]);
if(top_chamfer_h)
@ -146,7 +152,7 @@ module thread(dia, pitch, length, profile, center = true, top = -1, bot = -1, st
else
difference() {
hull() {
translate([0, eps])
translate([0, offset])
square([r, len]);
translate([0, bot_chamfer_h])