POV-Ray : Newsgroups : povray.binaries.images : Problem with f_rounded_box function : Re: Problem with f_rounded_box function Server Time
17 May 2024 05:54:02 EDT (-0400)
  Re: Problem with f_rounded_box function  
From: Christoph Hormann
Date: 13 Mar 2006 04:25:03
Message: <dv3do9$j7c$1@chho.imagico.de>
Sebastian H. wrote:
> 
>> Sebastian H. wrote:
>>
>> That's not what i meant.  You don't need the sqrt() on the faces of 
>> the rounded cube - there a simple plane function is sufficient.
> 
> 
> Hmm, needs some "if" calls 

Yes, that's what i meant.  I would however do it somewhat differently 
(untested, based on what you wrote):

{
   DBL x2, y2, z2, x3, y3, z3;

   x2 = PARAM(1) - PARAM(0);
   y2 = PARAM(2) - PARAM(0);
   z2 = PARAM(3) - PARAM(0);

   x3 = fabs(PARAM_X);
   y3 = fabs(PARAM_Y);
   z3 = fabs(PARAM_Z);

   if (x3 < x2)
   {
     if (y3 < y2)
     {
       if (z3 < z2)
       {
         return -PARAM(0);
       }
       return (z3 - PARAM(3));
     }
     if (z3 < z2)
     {
       return (y3 - PARAM(2));
     }
     return (sqrt(PARAM_Y * PARAM_Y + PARAM_Z * PARAM_Z)  - PARAM(0));
   }

   if (y3 < y2)
   {
     if (z3 < z2)
     {
       return (x3 - PARAM(1));
     }
     return (sqrt(PARAM_X * PARAM_X + PARAM_Z * PARAM_Z)  - PARAM(0));
   }

   if (z3 < z2)
   {
     return (sqrt(PARAM_X * PARAM_X + PARAM_Y * PARAM_Y)  - PARAM(0));
   }

   return (sqrt(PARAM_X * PARAM_X + PARAM_Y * PARAM_Y + PARAM_Z * 
PARAM_Z)  - PARAM(0));
}

It would BTW be easy to add a correct distance function for the interior 
as well by replacing the 'return -PARAM(0);'.  This would of course 
break backwards compatibility so it might not be a good idea.

Christoph

-- 
POV-Ray tutorials, include files, Landscape of the week:
http://www.imagico.de/ (Last updated 31 Oct. 2005)
MegaPOV with mechanics simulation: http://megapov.inetart.net/


Post a reply to this message

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