POV-Ray : Newsgroups : povray.binaries.images : iso-sphere-sweep - second example : Re: iso-sphere-sweep - second example Server Time
16 Aug 2024 18:20:19 EDT (-0400)
  Re: iso-sphere-sweep - second example  
From: Tor Olav Kristensen
Date: 4 Jan 2002 22:35:02
Message: <3C3673FB.52F2CC76@hotmail.com>

> 
> another example of sphere sweep as on iso

I could not spot any non-connected cylinder
ends in that image, so I thought that maybe
the source code below could be of interest
for you.

But maybe you have figured this out already...


Tor Olav


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Copyright 2002 by Tor Olav Kristensen
// Email: tor### [at] hotmailcom
// http://www.crosswinds.net/~tok
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.5;

#include "colors.inc"

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

/*
// A macro that I once made.
// (Compare to the second macro to see similarities.)

#macro Dist2LnSegm(pP, pA, pB)

    #local vL = pB - pA;
    #local ss = vdot(pP - pA, vL)/vdot(vL, vL);

    vlength(pP - pA - max(0, min(ss, 1))*vL)

#end // Dist2LnSegm
*/

#macro CylinderFunction(pA, pB, Radius)

  #local Ax = pA.x;
  #local Ay = pA.y;
  #local Az = pA.z;
  #local vL = pB - pA;
  #local Lx = vL.x;
  #local Ly = vL.y;
  #local Lz = vL.z;
  #local LL = vdot(vL, vL);
  #local vD = vL/LL;
  #local Dx = vD.x;
  #local Dy = vD.y;
  #local Dz = vD.z;
  #local AD = vdot(pA, vD);

  function {
    sqrt(
      (x - Ax - max(0, min(x*Dx + y*Dy + z*Dz - AD, 1))*Lx)^2
     +(y - Ay - max(0, min(x*Dx + y*Dy + z*Dz - AD, 1))*Ly)^2
     +(z - Az - max(0, min(x*Dx + y*Dy + z*Dz - AD, 1))*Lz)^2
    )
   -Radius
  }

#end // macro CylinderFunction


/*
Some notes about the macro above.

Distance from pP = <x, y, z> to line segment between pA and pB is:

Dist = vlength(pP - pA - max(0, min(ss, 1))*vL)

where ss =
vdot(pP - pA, vL)/vdot(vL, vL) =
vdot(pP - pA, vL)/LL =
(vdot(pP, vL) - vdot(pA, vL))/LL =
vdot(pP, vL)/LL - vdot(pA, vL)/LL =
vdot(pP, vL/LL) - vdot(pA, vL/LL) =
vdot(pP, vD) - vdot(pA, vD) =
vdot(pP, vD) - AD =
pP.x*vD.x + pP.y*vD.y + pP.z*vD.z - AD =
x*Dx + y*Dy + z*Dz - AD

Distance from pP to cylinder "between" pA and pB is:

Dist - Radius
*/

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare p1 = <-3, 2, 4>;
#declare p2 = <2, -1, 0>;
#declare R = 0.5;

#declare MyCylFn = CylinderFunction(p1, p2, R)

isosurface {
  function { MyCylFn(x, y, z) }
  contained_by { sphere { <0, 0, 0>, 6 } }
  pigment { color White }
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

background { color (Blue + Cyan)/4 }

light_source {
  <3, 3, -2>*10
  color White
}

camera {
  location -5*z
  look_at 0*y
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

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