POV-Ray : Newsgroups : povray.general : rounded_objects: a new feature? : Re: rounded_objects: a new feature? Server Time
22 Jun 2024 06:43:10 EDT (-0400)
  Re: rounded_objects: a new feature?  
From: John Greenwood
Date: 20 Sep 2016 06:25:01
Message: <web.57e10dd0696ad3a7cafab50@news.povray.org>
scott <sco### [at] scottcom> wrote:
> >>> If you're on to something then some working
> >>> example code will go *far* further than just a text description.
> >>
> >> Totally agree, I am working on it.
> >
> > And here it is:
>
> A good start!
>
> How would you go about doing the union (or difference) of two rounded
> cubes? I tried to modify the code to do this but couldn't get it to
> work. If that works nicely then I think you're on to something...

Like this:

// This work is licensed under the Creative Commons Attribution 3.0 Unported
License.
// To view a copy of this license, visit
http://creativecommons.org/licenses/by/3.0/
// or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain
View,
// California, 94041, USA.

// Demonstration of subtraction for rounded objects

// Vers: 1.00
// Date: 20 Sept 2016
// Auth: John Greenwood

#version 3.7 ;

#include "colors.inc"

camera {location <10,7,30> angle 15 look_at <0,0,0> }

  background { color rgb<0.2, 0.4, 0.8>  }
  light_source {<10,5,10> color White}
  global_settings {assumed_gamma 1.0 }


  #declare R_function = function( F,q,p,n){

select((F>q)-(F<-q),2*(q<0)-1,p*pow(F/q,5)-(2*p+.5)*pow(F/q,3)+(1.5+p)*F/q,1-2*(q<0))+n

                                        }

  #declare Vo =1;
    #declare R_limit = function(V){select((V+1>Vo)-(V+1<-Vo),
-1,-.5*pow((V+1)/Vo,3)+1.5*(V+1)/Vo,+1)-1}


  #declare Corner_Profile = -0;   // -.5 gives rounded bevel, 0 almost round,
+.5 Not noticebly sharper
  #declare Corner_round = .3;

  isosurface {
     function    {

            +   R_function(-sqrt(pow(x-1,2)+pow(y,2)+pow(z,2))+1.5,-.3,0,-1)

  +R_limit(
                 R_function(x-1,+Corner_round,Corner_Profile,1)
              +R_function(x+1,-Corner_round,Corner_Profile,1)
              +R_function(y-1, Corner_round,Corner_Profile,1)
              +R_function(y+1,-Corner_round,Corner_Profile,1)
              +R_function(z-1,+Corner_round,Corner_Profile,1)
              +R_function(z+1,-Corner_round,Corner_Profile,1)-2 )


             +3      //Increasing this by two gives the intersection
                 }
     threshold 0
      max_gradient 20
     contained_by { box { -2, 2 } }
  texture {pigment {color rgb < 1, 0.9, 0.65>}}
      translate < -2.5,1.5,0>
               }


  isosurface {
     function    {

            +
R_function(-sqrt(pow(x+.8,2)+pow(y+.5,2)+pow(z+1,2))+1.5,-.3,0,-1)

  -R_limit(
                 R_function(x-1.5,+Corner_round,Corner_Profile,1)
              +R_function(x+1,-Corner_round,Corner_Profile,1)
              +R_function(y-1.5, Corner_round,Corner_Profile,1)
              +R_function(y+1,-Corner_round,Corner_Profile,1)
              +R_function(z-1.5,+Corner_round,Corner_Profile,1)
              +R_function(z+1,-Corner_round,Corner_Profile,1)-2 )


             +1
                 }
     threshold 0
      max_gradient 20
     contained_by { box { -2, 2 } }
  texture {pigment {color rgb < 1, 0.9, 0.65>}}
      translate < 2.5,-1.5,0>
               }


  isosurface {
     function    {

            -   R_function(-sqrt(pow(x-1,2)+pow(y-.5,2)+pow(z-1,2))+1,-.3,0,-1)

  +R_limit(
                 R_function(x+1.5,-Corner_round,Corner_Profile,1)
              +R_function(x-1,+Corner_round,Corner_Profile,1)
              +R_function(y-1.5, Corner_round,Corner_Profile,1)
              +R_function(y+1,-Corner_round,Corner_Profile,1)
              +R_function(z-1.5,+Corner_round,Corner_Profile,1)
              +R_function(z+1,-Corner_round,Corner_Profile,1)-2 )


             +1
                 }
     threshold 0
      max_gradient 20
     contained_by { box { -2, 2 } }
  texture {pigment {color rgb < 1, 0.9, 0.65>}}
      translate < 2.5,1.3,0>
               }


  isosurface {
     function    {

        - R_limit(
                 R_function(-sqrt(pow(x-.5,2)+pow(z,2))+1,-.3,0,-1)
                +R_function(y-1 ,+.3,0,1)
                +R_function(y+1,-.3,0,1))

       +R_limit( R_function(-sqrt(pow(x+.5,2)+pow(z,2))+1,-.3,0,-1)
                +R_function(y-1.5,+.3,0,1)
                +R_function(y+1.5,-.3,0,1))
                +1
                 }
     threshold 0
      max_gradient 20
     contained_by { box { -2, 2 } }
  texture {pigment {color rgb < 1, 0.9, 0.65>}}
      translate < -2.5,-1.5,0>

               }


Post a reply to this message

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