POV-Ray : Newsgroups : povray.text.scene-files : Machine screw isosurface functions Server Time
29 Mar 2024 11:05:16 EDT (-0400)
  Machine screw isosurface functions (Message 1 to 3 of 3)  
From: Cousin Ricky
Subject: Machine screw isosurface functions
Date: 18 Jun 2020 22:39:56
Message: <5eec257c$1@news.povray.org>
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,
         HTRI2 / (2 * 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,
         P2FACTOR / 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]----------
#declare fn_Screw_hole_radius = function (P0_Dmajor, P1_Thread_count)
{ P0_Dmajor / 2 - 5 * sqrt(3) / (16 * P1_Thread_count)
}
-----------[END CODE]-----------


Post a reply to this message

From: kurtz le pirate
Subject: Re: Machine screw isosurface functions
Date: 21 Jun 2020 05:24:57
Message: <5eef2769$1@news.povray.org>
On 19/06/2020 04:39, Cousin Ricky wrote:
> 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.
> ...
> 
  I made a simple scene to compare the first two functions.
Image contains 100 screws :

             without aa   with aa
Function 1    12.133"    38.230"
Function 2    11.752"    34.931
               -3.1%       -8.6%

The second function is definitely the best.
Better and faster rendering.


Very good job Cousin Ricky !


-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message

From: Cousin Ricky
Subject: Re: Machine screw isosurface functions
Date: 21 Jun 2020 12:35:00
Message: <web.5eef8b632665c08c60e0cc3d0@news.povray.org>
Cousin Ricky <ric### [at] yahoocom> wrote:
> radius.  Since it's likely use is at parse time, not in isosurfaces, I
                   ^

AAAARGH!!!  I hate it when I do that!


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.