POV-Ray : Newsgroups : povray.general : Connecting cylinders with chunks of a torus vs. sphere_sweep point cloud. : Re: Connecting cylinders with chunks of a torus vs. sphere_sweep point clou= Server Time
29 Jul 2024 10:30:31 EDT (-0400)
  Re: Connecting cylinders with chunks of a torus vs. sphere_sweep point clou=  
From: JimT
Date: 21 Oct 2011 11:50:00
Message: <web.4ea1942e24984897be7517870@news.povray.org>
> > If you want the macro, I can send it.
>
> Please do, thanks! :)
>
This seems to work.

ft is the multiple of the distance between cylinder ends used for the position
of the internal control points along the line of each cylinder axis. Should give
a proportionate loop for cylinders separated by differing distances.

#include "colors.inc"
//
global_settings {max_trace_level 15}
//
background{White}
//
#macro SF_roundcone(bigend,smallend,bigrad,smallrad)
//
// bigend, smallend are vectors, bigrad, smallrad are scalars
//
//#warning concat("bigrad   is:",str(bigrad,7,3),"\n")
//#warning concat("smallrad is:",str(smallrad,7,3),"\n")
#local big2small = smallend-bigend;
#local el        = vlength(big2small);
#local big2small = big2small/el;
#local ex        = smallrad*el/(bigrad - smallrad);
#local sinalpha  = smallrad/ex;
#local cosalpha  = sqrt(1-sinalpha*sinalpha);
#local conebig   = bigend + (bigrad*sinalpha)*big2small;
#local conesmall = smallend + (smallrad*sinalpha)*big2small;
//
union{
   sphere{smallend smallrad}
   sphere{bigend bigrad}
   cone{conebig bigrad*cosalpha conesmall smallrad*cosalpha}
     }
//
#end
//
#macro SF_snake(nsegs,p1,p2,p3,p4,r1,r2,r3,r4)
//
// nsegs Number of segmennts
// p1-p4 Positions of Bezier Spline control points
// r1-r4 Radii of shape used as Bezier control points
//
  #local pLast = p1;
  #local rLast = r1;
  #local icount = 0;
  union{
    #while(icount< nsegs)
      #local icount = icount + 1;
      #local tNow = icount/nsegs;
      #local f1 = (1-tNow)*(1-tNow)*(1-tNow);
      #local f2 = 3*tNow*(1-tNow)*(1-tNow);
      #local f3 = 3*tNow*tNow*(1-tNow);
      #local f4 = tNow*tNow*tNow;
      #local pNow = f1*p1+f2*p2+f3*p3+f4*p4;
      #local rNow = f1*r1+f2*r2+f3*r3+f4*r4;
//
      #if(rNow > rLast)
        object{SF_roundcone(pNow,pLast,rNow,rLast)}
      #else
        #if(rNow < rLast)
          object{SF_roundcone(pLast,pNow,rLast,rNow)}
        #else
          sphere{pNow rNow}
          sphere{pLast rLast}
          cylinder{pNow pLast rLast}
        #end
      #end
      #local pLast = pNow;
      #local rLast = rNow;
    #end
        }
#end
// First cylinder
#declare p11 = <0,0,0>;
#declare p12 = <0,4,0>;
#declare r11 = 1;
//Second cylinder
#declare p21 = <3,0,0>;
#declare p22 = <4,3,2>;
#declare r22 = 0.5;
//
// Bigger ft gives loopier blend
#declare ft = 1.5;
//
#declare cyldist = vlength(p12-p22);
//
#declare p1 = p12;
#declare p2 = p12+ft*cyldist*(p12-p11)/vlength(p12-p11);
#declare p3 = p22+ft*cyldist*(p22-p21)/vlength(p12-p11);
#declare p4 = p22;
//
#declare r1 = r11;
#declare r2 = r11;
#declare r3 = r22;
#declare r4 = r22;
//
#declare nsegs = 50;
//
#declare cylblend = union{
                      cylinder{p11 p12 r11 pigment{Red}}
                      cylinder{p21 p22 r22 pigment{Green}}
                      object{SF_snake(nsegs,p1,p2,p3,p4,r1,r2,r3,r4)
pigment{Blue}}
                         }
object{cylblend translate <0,-3,0>}
object{cylblend rotate <0,45,0> translate <0,-3,7>}
object{cylblend rotate <0,-45,0> translate <0,-3,-7>}
//
camera {orthographic location <15,0,0> look_at <0,0,0>}
light_source {<400,200,-300> rgb <1, 1, 1.00> shadowless}


Post a reply to this message

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