POV-Ray : Newsgroups : povray.general : There must be a better way to do threads Server Time
16 Nov 2024 03:22:17 EST (-0500)
  There must be a better way to do threads (Message 1 to 6 of 6)  
From: Jack Twilley
Subject: There must be a better way to do threads
Date: 25 Mar 2004 09:18:05
Message: <86brml810l.fsf@duchess.twilley.org>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I've googled for examples on threads (on bolts and the like) and I've
written a macro that looks like this:

#macro do_threads (turns, start, length, outer, inner, perturn)
union {
  #local index = 0;
  #local total = 360*turns;
  #while (index < total)
    #local zee = start+index*length/total;
    cone {
      <outer, 0, zee> length/turns <inner, 0, zee> 0
      rotate index*z
    }
    #local index = index + 360/perturn;
  #end
}
#end

This macro creates a jillion (well, perturn*turns) cones to simulate a
triangular spiral prism.  It works, but it's ugly and slow as a dog.
Please tell me that there's a better way.  I stared at the docs for
lathe and prism, and I couldn't see anything useful there.

Help?

Jack.
- -- 
Jack Twilley
jmt at twilley dot org
http colon slash slash www dot twilley dot org slash tilde jmt slash
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)

iD8DBQFAYuneGPFSfAB/ezgRAoMGAJ0aaJINe5OpXNP7UMxa9j1/coNovACgnBUu
MlX93neI9Bx0USOF+Tt13pE=
=Jafi
-----END PGP SIGNATURE-----


Post a reply to this message

From: Alf Peake
Subject: Re: There must be a better way to do threads
Date: 25 Mar 2004 10:34:24
Message: <4062fc00@news.povray.org>
Hi Jack

Have you tried pov's helix function (the thread shape does not have to
be round)?

Try playing with this:

//Start extract
#include "functions.inc"

// Bolt - thread is made 4 times larger.
#declare Thread =
isosurface {
  function{ f_helix1(x,y,z, 1, 40, 0.12, 0.28, 0.7, 2, 0) }
  contained_by{ box{ <-0.5,-3,-0.5>,<0.5,-0.6,0.5> } }
  accuracy 0.0001
  max_gradient 1.7
}

#declare Bolt =
difference{
   union{
      cylinder{ 0, y*0.3, 0.3 } // Head
      object{ Thread scale 0.25 }
      cylinder{ -y*0.75, -y*0.1, 0.07 }
      cylinder{ <0,-0.15,0>, <0,0.05,0>, 0.1 }
   }
   torus{ 0.1, 0.04 translate -y*0.15 }
   box{ <-0.05,0.2,-0.4>, <0.05,0.35,0.4> }
}
// End extract

You can see an example of these here:
http://www.peake42.freeserve.co.uk/pix1/tape.jpg

There is also a "Nut and Bolt" macro out there somewhere (also try
p.b.s-f and p.t.s-f).


-- 
Alf

http://www.peake42.freeserve.co.uk/
http://www.qsl.net/gw3srg/


Post a reply to this message

From: Jack Twilley
Subject: Re: There must be a better way to do threads
Date: 25 Mar 2004 11:41:10
Message: <861xng98yk.fsf@duchess.twilley.org>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I hadn't tried f_helix[12] or f_spiral because I couldn't find any
example code using them, and I've never used isosurfaces before.

If f_helix1 will allow me to create a triangular spiral prism, then
I'm all set.  I'll tinker with the code you've posted (it all makes
sense except the isosurface stuff) and see if I can make it work.

Thanks!

Jack.
- -- 
Jack Twilley
jmt at twilley dot org
http colon slash slash www dot twilley dot org slash tilde jmt slash
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)

iD8DBQFAYwtoGPFSfAB/ezgRAnbNAKCYiG2uygYwb13LAwMfVamzPqIScACgjNj2
jKq9N+VQxr59jYH4dBo5b6E=
=2Alh
-----END PGP SIGNATURE-----


Post a reply to this message

From: Samuel T  Benge
Subject: Re: There must be a better way to do threads
Date: 25 Mar 2004 11:51:50
Message: <40630DF0.7080202@hotmail.com>
Jack Twilley wrote:

 > Help?

Hello Jack.

Here's a simple way using an isosurface and a declared pattern to make 
triangular threads:

#declare threads=
  function{
   pattern{ spiral1 1 rotate x*90 triangle_wave}
  }

isosurface {
  function{
   // cylinder, with a radius of 5 units
   sqrt(x*x+z*z)-5
   // threads
   +threads(x,y,z)/4
  }
  accuracy .01
  evaluate 5, 1.2, 0.95
  contained_by{ box{<-5,-10,-5>,<5,10,5>} }
  pigment{rgb .1}
  finish{reflection .9 specular 1 roughness .05}
}

If I think of anything else, like a faster method, I'll post more code.

-Samuel Benge


Post a reply to this message

From: Christopher James Huff
Subject: Re: There must be a better way to do threads
Date: 25 Mar 2004 13:49:36
Message: <cjameshuff-7E0E3C.13495525032004@news.povray.org>
In article <86b### [at] duchesstwilleyorg>,
 Jack Twilley <jmt+use### [at] twilleyorg> wrote:

> This macro creates a jillion (well, perturn*turns) cones to simulate a
> triangular spiral prism.  It works, but it's ugly and slow as a dog.
> Please tell me that there's a better way.  I stared at the docs for
> lathe and prism, and I couldn't see anything useful there.

There are several better ways. You could build a mesh or use an 
isosurface, for example. The mesh would probably be faster, the 
isosurface would use less memory and wouldn't have faceting problems.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: Christopher James Huff
Subject: Re: There must be a better way to do threads
Date: 25 Mar 2004 13:52:29
Message: <cjameshuff-D5E66C.13524825032004@news.povray.org>
In article <cjameshuff-7E0E3C.13495525032004@news.povray.org>,
 Christopher James Huff <cja### [at] earthlinknet> wrote:

> There are several better ways. You could build a mesh or use an 
> isosurface, for example. The mesh would probably be faster, the 
> isosurface would use less memory and wouldn't have faceting problems.

BTW, an easy method of generating a mesh would be to use the 
cylinderical height field macro in shapes.inc. Just use a spiral pattern 
function to bring out the threads.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

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