POV-Ray : Newsgroups : povray.text.scene-files : Machine screw isosurface functions : Machine screw isosurface functions Server Time 2 Mar 2024 15:07:55 EST (-0500)
 Machine screw isosurface functions
 From: Cousin Ricky Date: 18 Jun 2020 22:39:56 Message: <5eec257c\$1@news.povray.org>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#5eec257c%241%40news.povray.org",
"dateCreated": "2020-06-19T02:39:56+00:00",
"datePublished": "2020-06-19T02:39:56+00:00",
"author": {
"@type": "Person",
"name": "Cousin Ricky"
}
}
This function will create standard machine screw right-handed threading.
It accepts major diameter and thread count as arguments, and it should
work for both USA and metric sizes.  (The geometry has been standardized
internationally.)  The shaft is oriented vertically.  In order to
minimize square root calculations within the runtime loop, a constant is
declared outside the function.

----------[BEGIN CODE]----------
#include "functions.inc"

#local HTRI2 = sqrt(3);

#declare fn_Screw = function (x, y, z, P0_Dmajor, P1_Thread_count)
{ max
( min
( f_helix1
( -x, y, z, 1, 2*pi * P1_Thread_count,
P0_Dmajor / 2 - 0.4375 * HTRI2 / P1_Thread_count,
1 / HTRI2, 2, 0
),
f_sphere (x, 0, z, P0_Dmajor / 2 - 0.3125 * HTRI2 / P1_Thread_count)
),
f_sphere (x, 0, z, P0_Dmajor / 2)
)
}
-----------[END CODE]-----------

To get left-handed threading, replace the -x with x.

As a sanity check, I compared my function to Robert Munyer's post from
last June.  Despite the differences in form, the numbers turn out to be
the same.

This next function is less straightforward, because it entails twisting
a square and the re-scaling that entails, but it renders slightly
faster.  I saved about 7% in tests.

----------[BEGIN CODE]----------
#include "functions.inc"

#local HTRI2 = sqrt(3);
#local P2FACTOR = sqrt(3/8);

#declare fn_Screw = function (x, y, z, P0_Dmajor, P1_Thread_count)
{ max
( min
( f_helix1
( -x, y, z, 1, 2*pi * P1_Thread_count,
P0_Dmajor / 2 - 0.4375 * HTRI2 / P1_Thread_count,
1 / HTRI2, 0, 45
),
f_sphere (x, 0, z, P0_Dmajor / 2 - 0.3125 * HTRI2 / P1_Thread_count)
),
f_sphere (x, 0, z, P0_Dmajor / 2)
)
}
-----------[END CODE]-----------

The one disadvantage of the above functions is that they are too
perfect.  With the sharp angles, it is difficult to get good highlights
and avoid that "ray-traced look."  I'm sure there's some normals trick
or proximity macro that can improve the look, and I'm even
half-considering writing a tedious function for a softer version of
those hills and valleys; but if there's no need for a close-up of the
screws, this next function can get you some shiny screws of a reasonable
form.

----------[BEGIN CODE]----------
#include "functions.inc"

#local HTRI = sqrt (3/4);

#declare fn_Screw = function
( x, y, z, P0_Dmajor, P1_Thread_count
)
{ f_sphere
(   x, 0, z,
P0_Dmajor / 2
- (1 - cos (y * 2*pi * P1_Thread_count + atan2 (x, z)))
* 0.3125 * HTRI / P1_Thread_count
)
}
-----------[END CODE]-----------

If you wish to model screw holes but don't want to bother modeling the
internal threads, this function will give you the proper internal
radius.  Since it's likely use is at parse time, not in isosurfaces, I
have not bothered to pre-declare any constants.  Note that, as written,
it accepts a diameter but returns a radius.

----------[BEGIN CODE]----------