POV-Ray : Newsgroups : povray.general : Isofunctions and meshes Server Time
24 Dec 2024 11:22:43 EST (-0500)
  Isofunctions and meshes (Message 1 to 10 of 24)  
Goto Latest 10 Messages Next 10 Messages >>>
From: John Greenwood
Subject: Isofunctions and meshes
Date: 30 Nov 2016 07:10:00
Message: <web.583ec0fadcdf42f1a7cafab50@news.povray.org>
I have added another capability to my rounded corners idea, demonstrated by the
code below. (I intend to add a description of how this works to
http://www.john-greenwood.co.uk/PovRay/Rounded_Objects/Basics.html)

Designing objects like the one in this demo badly needs a fast display to check
the effect of changes to the controlling parameters.

I have used the isofunction for this development and have given priority to
clarity of working over speed of rendering. However I think the isofunction
approach is always going to be slow.

I am wondering if a better approach might be to realise the rounded object as a
mesh which, I understand, would render much faster. I have had a quick look at
meshes in the PovRay documentation but am not at all clear how it could be used
in this case.

Another option would to be to do the design with a separate app such as
Bishop3D. Currently this does not do isofunctions but I am trying to contact the
author to find out how the development is going.

// Rounded objects: Illustration of R_Surface

// Vers: 1.00
// Date: 30 Nov 2016
// Auth: John Greenwood

#version 3.7 ;
    global_settings {assumed_gamma 1.0 }
    camera {location <-30,10,-40> angle 9 look_at <0,0,0> }
    light_source {<-5,20,-20> colour rgb<1,1,1>}
    background { color rgb<0.2, 0.4, 0.8>  }

// The essential functions******************************************
  #declare R_function = function( p,F){
    select(-(p<=-1) , select((F>1)-(F<-1) , -1 , F , 1)+1
                 , select(-(p!=1) , select((F>1)-(F<-1) , -1 ,
..5*p*pow(F,5)-(p+.5)*pow(F,3)+(1.5+.5*p)*F , 1)+1
                               ,F/(sqrt(.17+pow(F,2))) +1
           ) )
                                 }

  #declare R_Intersection =
function(V){select((V>2)-(V<0),-1,-.5*pow(V-1,3)+1.5*(V-1),+1)+1}
  #declare R_Union =
function(V){select((V>4)-(V<2),-1,-.5*pow(V-3,3)+1.5*(V-3),+1)+1}
  #declare R_Unite =
function(n,V){select((V>(2*n))-(V<2*n-2),-1,-.5*pow(V+1-2*n,3)+1.5*(V+1-2*n),+1)+1}

  #declare R_S_function = function( p,x,y,z,F){
    select(-(p<=-1) , select((F>1)-(F<-1) , -1 , F , 1)+1
                 , select(-(p!=1) , select((F>1)-(F<-1) , -1 ,
..5*p*pow(F,5)-(p+.5)*pow(F,3)+(1.5+.5*p)*F , 1)+1
                               ,F/(sqrt(.17+pow(F,2))) +1
           ) )
                                 }


  #declare R_Ridge =function(Dim,Off,Width){1/(1+pow((Dim+Off)/Width,2))}
  #declare R_Step
=function(Dim,Off,Width){.5+.5*(Dim+Off)/(Width*sqrt(1+pow((Dim+Off)/Width,2)))}
  #declare R_Bend
=function(Dim,Off,Width){Width*(sqrt(1+pow((Dim+Off)/Width,2))-1)}
  #declare R_Surface =
function(p,r,L,xo,yo,zo,x,y,z,Fm){R_S_function(p,x,y,z,((x*xo+y*yo+z*zo)/sqrt(pow(xo,2)+pow(yo,2)+pow(zo,2))
+L+Fm) /-r)}
//**********************************************************************

  #declare R_Sphere =
function(p,r,L,x,y,z){R_function(p,(sqrt(pow(x,2)+pow(y,2)+pow(z,2))-L)/r) }


#ifndef(s) #local s = 0; #end

//Rounded object work
bench----------------------------------------------------------------

  #declare EyeSep =     .7;
  #declare EyeProtrude = 1.4;
  #declare EyeBallRad = .5;
  #macro Face(r) +R_Surface(.6,r,2,0,0,+1,x,y,z,
..4*R_Step(y,-.2,.2)-.2*R_Bend(y,0,2)-.2*R_Bend(x,0,.5)-.1*R_Ridge(x,0,1)*(R_Ridge(y,-.8,.1)+R_Ridge(y,-1,.1)))
#end

  #declare Head = function(x,y,z){
     R_Intersection(
                 Face(2)
                +R_Surface(.6,3,2,0,+.3,-1,x,y,z,0)

                +R_Surface(.6,1,2,  +1, .15,0,x,y,z,-.2*R_Bend(y,0,1))
                +R_Surface(.6,1,2,  -1,+.15,0,x,y,z,-.2*R_Bend(y,0,1))

                +R_Surface(.6,.7,3,0,+1,0,x,y,z,0)
                +R_Surface( 1,3 ,2.7,0,-1,0,x,y,z,-.5*R_Bend(x,0,1))


                +R_Sphere(.6,-.7,.12,x-EyeSep,y+.3 ,z+2)
                +R_Sphere(.6,-.7,.12,x+EyeSep,y+.3 ,z+2)
                     ) }

  #declare Nose =
     function(x,y,z){
     R_Intersection(
                +R_Surface(.6,.6,.5,  +1, -.25, +.4, x,y,z,0)
                +R_Surface(.6,.6,.5,  -1, -.25, +.4, x,y,z,0)

                +R_Surface(.6,.3,.4,   0,  +1,   0, x,y,z,0)
                +R_Surface(.6,.4,.7,   0,   0,   -1, x,y,z,0)
                    )
                     }

//Mouth----------------------------

   isosurface {
    function{
     R_Intersection(
                 Face(.1)
                +R_Surface(.6,.2,-.6,  0,+1,0,
x,y,z,+.5*(R_Step(x,+.5,.2)-R_Step(x,-.5,.2)+R_Step(z,+3,.2)-R_Step(z,1,.2)))
                +R_Surface(.6,.2, .0,  0,-1,0, x,y,z,0)
                    )
                     }
     threshold 1
      max_gradient 25
     contained_by { box {<-1,-.5, -1>, <1,.5,-3>} }
  texture {pigment {color rgb < 1, .3,.3>}}
     translate <0,-1.6,+.15>          }


//------------------------------------------------------------------------------------------

  isosurface {
     function  {
// start of rounded object ****************************************
    R_Union(
              Head(x,y,z)
              +Nose(x,y+.8,z+EyeProtrude-.1)
              )
// end of rounded object **************************

                     }
     threshold 1
      max_gradient 11
     contained_by { box {<-2.5,-3.2, -2.5>, <2.5,3.2,2.5>} }
  texture {pigment {color rgb < 1, 0.9, 0.65>}}

               }



  #declare EyeBall =
    #union {
     sphere {0,EyeBallRad pigment {color rgb < 1, 1, 1>}}
     sphere {<0,0,-.05-.5*EyeBallRad>,.5*EyeBallRad pigment {color rgb < 0, 0,
..2>}}

      finish {ambient .2 diffuse .6 specular 1 roughness .001 reflection {1}}
            }

 object {EyeBall translate < EyeSep,0,-EyeProtrude> }
 object {EyeBall translate <-EyeSep,0,-EyeProtrude> }


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Isofunctions and meshes
Date: 1 Dec 2016 04:40:01
Message: <web.583fef96b9cec73df14954290@news.povray.org>
"John Greenwood" <joh### [at] john-greenwoodcouk> wrote:
....
> // Rounded objects: Illustration of R_Surface
....
>   #declare R_function = function( p,F){
>     select(-(p<=-1) , select((F>1)-(F<-1) , -1 , F , 1)+1
>                  , select(-(p!=1) , select((F>1)-(F<-1) , -1 ,
> ..5*p*pow(F,5)-(p+.5)*pow(F,3)+(1.5+.5*p)*F , 1)+1
>                                ,F/(sqrt(.17+pow(F,2))) +1
>            ) )
>                                  }
....
>   #declare R_S_function = function( p,x,y,z,F){
>     select(-(p<=-1) , select((F>1)-(F<-1) , -1 , F , 1)+1
>                  , select(-(p!=1) , select((F>1)-(F<-1) , -1 ,
> ..5*p*pow(F,5)-(p+.5)*pow(F,3)+(1.5+.5*p)*F , 1)+1
>                                ,F/(sqrt(.17+pow(F,2))) +1
>            ) )
>                                  }

It seems to me that the R_function(p, F) and the R_S_function(p, x, y, z, F)
above will give the same result, as the x, y and z values are not used in the
R_S_function.

Is this what you intended ?

--
Tor Olav
http://subcube.com


Post a reply to this message

From: John Greenwood
Subject: Re: Isofunctions and meshes
Date: 1 Dec 2016 05:35:01
Message: <web.583ffc46b9cec73de15d43a80@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> "John Greenwood" <joh### [at] john-greenwoodcouk> wrote:
> ....
> > // Rounded objects: Illustration of R_Surface
> ....
> >   #declare R_function = function( p,F){
> >     select(-(p<=-1) , select((F>1)-(F<-1) , -1 , F , 1)+1
> >                  , select(-(p!=1) , select((F>1)-(F<-1) , -1 ,
> > ..5*p*pow(F,5)-(p+.5)*pow(F,3)+(1.5+.5*p)*F , 1)+1
> >                                ,F/(sqrt(.17+pow(F,2))) +1
> >            ) )
> >                                  }
> ....
> >   #declare R_S_function = function( p,x,y,z,F){
> >     select(-(p<=-1) , select((F>1)-(F<-1) , -1 , F , 1)+1
> >                  , select(-(p!=1) , select((F>1)-(F<-1) , -1 ,
> > ..5*p*pow(F,5)-(p+.5)*pow(F,3)+(1.5+.5*p)*F , 1)+1
> >                                ,F/(sqrt(.17+pow(F,2))) +1
> >            ) )
> >                                  }
>
> It seems to me that the R_function(p, F) and the R_S_function(p, x, y, z, F)
> above will give the same result, as the x, y and z values are not used in the
> R_S_function.
>
> Is this what you intended ?
>
> --
> Tor Olav
> http://subcube.com

Yes I think so. It seems that the x,y,z is needed when it is a function within a
function as in R_Surface.  I am nesting functions 5 deep and it looks like the
x,y,z needs to be "passed down" but I am not clear exactly what the rules are.
The x,y,z is a bit of clutter for the user.


Post a reply to this message

From: clipka
Subject: Re: Isofunctions and meshes
Date: 1 Dec 2016 05:47:48
Message: <583fffd4@news.povray.org>
Am 01.12.2016 um 11:34 schrieb John Greenwood:

> Yes I think so. It seems that the x,y,z is needed when it is a function within a
> function as in R_Surface.  I am nesting functions 5 deep and it looks like the
> x,y,z needs to be "passed down" but I am not clear exactly what the rules are.
> The x,y,z is a bit of clutter for the user.

That shouldn't be the case -- unless the functions further down the
rabbit hole actually try to access x,y,z.

There's essentially just one special case with regards to x,y,z: If you
specify a function without a parameter list, it will default to (x,y,z).


Post a reply to this message

From: John Greenwood
Subject: Re: Isofunctions and meshes
Date: 1 Dec 2016 06:35:00
Message: <web.58400adcb9cec73de15d43a80@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Am 01.12.2016 um 11:34 schrieb John Greenwood:
>
> > Yes I think so. It seems that the x,y,z is needed when it is a function within a
> > function as in R_Surface.  I am nesting functions 5 deep and it looks like the
> > x,y,z needs to be "passed down" but I am not clear exactly what the rules are.
> > The x,y,z is a bit of clutter for the user.
>
> That shouldn't be the case -- unless the functions further down the
> rabbit hole actually try to access x,y,z.
>
> There's essentially just one special case with regards to x,y,z: If you
> specify a function without a parameter list, it will default to (x,y,z).

In the line:
  #declare R_Surface =
function(p,r,L,xo,yo,zo,x,y,z,Fm){R_S_function(p,x,y,z,((x*xo+y*yo+z*zo)/sqrt(pow(xo,2)+pow(yo,2)+pow(zo,2))
+L+Fm) /-r)}

Substituting R_function for R_S_function no longer works. I think this is
because Fm is a function that contains functions of x,y,z.

R_function works when it is at the bottom of the hole as in this example from a
previous post:
  #declare R_Object1 =
     function(x,y,z){
        R_Intersection(
                +R_function(p,(x  +(4)) /-r)


Post a reply to this message

From: clipka
Subject: Re: Isofunctions and meshes
Date: 1 Dec 2016 06:52:30
Message: <58400efe$1@news.povray.org>
Am 01.12.2016 um 12:34 schrieb John Greenwood:
> clipka <ano### [at] anonymousorg> wrote:
>> Am 01.12.2016 um 11:34 schrieb John Greenwood:
>>
>>> Yes I think so. It seems that the x,y,z is needed when it is a function within a
>>> function as in R_Surface.  I am nesting functions 5 deep and it looks like the
>>> x,y,z needs to be "passed down" but I am not clear exactly what the rules are.
>>> The x,y,z is a bit of clutter for the user.
>>
>> That shouldn't be the case -- unless the functions further down the
>> rabbit hole actually try to access x,y,z.
>>
>> There's essentially just one special case with regards to x,y,z: If you
>> specify a function without a parameter list, it will default to (x,y,z).
> 
> In the line:
>   #declare R_Surface =
>
function(p,r,L,xo,yo,zo,x,y,z,Fm){R_S_function(p,x,y,z,((x*xo+y*yo+z*zo)/sqrt(pow(xo,2)+pow(yo,2)+pow(zo,2))
> +L+Fm) /-r)}
> 
> Substituting R_function for R_S_function no longer works. I think this is
> because Fm is a function that contains functions of x,y,z.
> 
> R_function works when it is at the bottom of the hole as in this example from a
> previous post:
>   #declare R_Object1 =
>      function(x,y,z){
>         R_Intersection(
>                 +R_function(p,(x  +(4)) /-r)

Can you attach an example scene file in povray.binaries.scene-files?


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Isofunctions and meshes
Date: 1 Dec 2016 07:10:01
Message: <web.5840129bb9cec73d28cdfe180@news.povray.org>
"John Greenwood" <joh### [at] john-greenwoodcouk> wrote:
> clipka <ano### [at] anonymousorg> wrote:
> > Am 01.12.2016 um 11:34 schrieb John Greenwood:
> >
> > > Yes I think so. It seems that the x,y,z is needed when it is a function within a
> > > function as in R_Surface.  I am nesting functions 5 deep and it looks like the
> > > x,y,z needs to be "passed down" but I am not clear exactly what the rules are.
> > > The x,y,z is a bit of clutter for the user.
> >
> > That shouldn't be the case -- unless the functions further down the
> > rabbit hole actually try to access x,y,z.
> >
> > There's essentially just one special case with regards to x,y,z: If you
> > specify a function without a parameter list, it will default to (x,y,z).
>
> In the line:
>   #declare R_Surface =
>
function(p,r,L,xo,yo,zo,x,y,z,Fm){R_S_function(p,x,y,z,((x*xo+y*yo+z*zo)/sqrt(pow(xo,2)+pow(yo,2)+pow(zo,2))
> +L+Fm) /-r)}
>
> Substituting R_function for R_S_function no longer works. I think this is
> because Fm is a function that contains functions of x,y,z.

This works:

#declare R_Surface =
  function(p, r, L, xo, yo, zo, x, y, z, Fm) {
    R_function(
      p,
      ((x*xo + y*yo + z*zo)/sqrt(pow(xo,2) + pow(yo,2) + pow(zo,2)) + L + Fm)/-r
    )
  }

Fm is not a function, it is a parameter that already contains a value when the
R_Surface function is evaluated, so x, y and z is not needed within the
R_Surface function for the purpose of calculating Fm.


Btw.:

If you do this:

#include "functions.inc"

Then you can replace this:

sqrt(pow(xo,2) + pow(yo,2) + pow(zo,2))

- with this:

f_r(xo, yo, zo)

--
Tor Olav
http://subcube.com


Post a reply to this message

From: John Greenwood
Subject: Re: Isofunctions and meshes
Date: 1 Dec 2016 11:00:00
Message: <web.58404720b9cec73de15d43a80@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> "John Greenwood" <joh### [at] john-greenwoodcouk> wrote:
> > clipka <ano### [at] anonymousorg> wrote:
> > > Am 01.12.2016 um 11:34 schrieb John Greenwood:

> >
> > Substituting R_function for R_S_function no longer works. I think this is
> > because Fm is a function that contains functions of x,y,z.
>
> This works:
>
> #declare R_Surface =
>   function(p, r, L, xo, yo, zo, x, y, z, Fm) {
>     R_function(
>       p,
>       ((x*xo + y*yo + z*zo)/sqrt(pow(xo,2) + pow(yo,2) + pow(zo,2)) + L + Fm)/-r
>     )
>   }
>
> Fm is not a function, it is a parameter that already contains a value when the
> R_Surface function is evaluated, so x, y and z is not needed within the
> R_Surface function for the purpose of calculating Fm.
>
>
> Btw.:
>
> If you do this:
>
> #include "functions.inc"
>
> Then you can replace this:
>
> sqrt(pow(xo,2) + pow(yo,2) + pow(zo,2))
>
> - with this:
>
> f_r(xo, yo, zo)
>
> --
> Tor Olav
> http://subcube.com

Thanks for showing me this. I need to look at it more closely.

But what about the main question: can my function which, is a single closed
surface, be turned into mesh?


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Isofunctions and meshes
Date: 1 Dec 2016 14:50:00
Message: <web.58407e12b9cec73de83a01320@news.povray.org>
"John Greenwood" <joh### [at] john-greenwoodcouk> wrote:
....
> Thanks for showing me this. I need to look at it more closely.
You are welcome.

> But what about the main question: can my function which, is a single closed
> surface, be turned into mesh?

Perhaps you can find something useful in this thread:

Subject: Isosurface Approximation macros rewrite
From: Tor Olav Kristensen
Date: 2008 February 22nd
Message: <47be20ab@news.povray.org>
Newsgroup: povray.binaries.scene-files

http://news.povray.org/povray.binaries.scene-files/thread/%3C47cc76fd@news.povray.org%3E/

--
Tor Olav
http://subcube.com


Post a reply to this message

From: John Greenwood
Subject: Re: Isofunctions and meshes
Date: 2 Dec 2016 08:05:01
Message: <web.584170a1b9cec73de15d43a80@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> "John Greenwood" <joh### [at] john-greenwoodcouk> wrote:

>> can my function, which is a single closed surface, be turned into mesh?
>
> Perhaps you can find something useful in this thread:
>
> Subject: Isosurface Approximation macros rewrite
> From: Tor Olav Kristensen
> Date: 2008 February 22nd
> Message: <47be20ab@news.povray.org>
> Newsgroup: povray.binaries.scene-files
>
>
http://news.povray.org/povray.binaries.scene-files/thread/%3C47cc76fd@news.povray.org%3E/
>
> --
> Tor Olav
> http://subcube.com

I have had a look and am floundering.

An example would be worth ten thousand words.

Could some kind person point me at an actual example of converting a simple
function, such as:
    function(x,y,z){sqrt(pow(x,2)+pow(y,2)+pow(z,2))-L)/r }
into a mesh object?


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

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