POV-Ray : Newsgroups : povray.advanced-users : Integration of Gradient functions. Fun with gradients :P Server Time
25 Nov 2024 05:16:37 EST (-0500)
  Integration of Gradient functions. Fun with gradients :P (Message 1 to 2 of 2)  
From: Pyry
Subject: Integration of Gradient functions. Fun with gradients :P
Date: 3 Sep 2003 04:00:02
Message: <web.3f559df779434d6b1f55322c0@news.povray.org>
I've been trying to get the inverse function of fn_Gradient_Directional(s)
and I think I finaly got it and here it is (named it fn_Integradient, just
copy it to your math.inc and it should work like the rest of the
Gradient-functions):






//Inverse of gradient_dir functions as a function by:Pyry Pakkanen
//_fn_Gradient_X;Y;Z is the vector-function component of the gradient at
//that point of space
//_Interations must even(2,4,6,20,100 etc.) It is not checked just in case
//someone wants to experiment with it :P
//High _Interations produces more accturate results but will be slower
//The method(Simpson) used is quite slow and does not always produce wanted
//results.
//(for example _fn_Gradient_X = function{y} _fn_Gradient_Y = function{0}
//creates a gradient in the y direction[wich should be zero] for the result
//function )
//anything like 1/x does not work because its infinite at <0,0,0> You'll
//have to move your gradient functions away from <0,0,0> first and move them
//back for the final function
//exapmle of usage:
/*
//Sphere with a noisy surface without "bubbles" that noise added to
//functions usually produces (the gradient of the noise gets higher than the
//gradient of the function)
//this is fixed by making the gradient of noise porpotional to the gradient
//of the function
#declare TTx =function{x/f_r(x,y,z)*pow(f_noise3d(x*4,y*4,z*4),3)*6};
#declare TTy =function{y/f_r(x,y,z)*pow(f_noise3d(x*4,y*4+100,z*4),3)*6};
#declare TTz =function{z/f_r(x,y,z)*pow(f_noise3d(x*4,y*4,z*4+100),3)*6};

#declare TT = fn_Integradient(TTx,TTy,TTz,40);//quite high _Interations
//have to be used
//Now TT(x,y,z)-1 can be used to make an isosurface (it looks like blobby
//combination of spikes)
//
*/

#macro
fn_Integradient(_fn_Gradient_X,_fn_Gradient_Y,_fn_Gradient_Z,_Interations)

function{0 //start at zero
 #local _C = 1;
  +(
   _fn_Gradient_X(x/_Interations,y/_Interations,z/_Interations)*x+
   _fn_Gradient_Y(x/_Interations,y/_Interations,z/_Interations)*y+
   _fn_Gradient_Z(x/_Interations,y/_Interations,z/_Interations)*z
   )/_Interations/3
 #while(_C<_Interations-1)
 #local _C = _C+1;
 +(
   _fn_Gradient_X(x*_C/_Interations,y*_C/_Interations,z*_C/_Interations)*x+
   _fn_Gradient_Y(x*_C/_Interations,y*_C/_Interations,z*_C/_Interations)*y+
   _fn_Gradient_Z(x*_C/_Interations,y*_C/_Interations,z*_C/_Interations)*z
   )/_Interations*4/3
 #local _C = _C+1;
 +(
   _fn_Gradient_X(x*_C/_Interations,y*_C/_Interations,z*_C/_Interations)*x+
   _fn_Gradient_Y(x*_C/_Interations,y*_C/_Interations,z*_C/_Interations)*y+
   _fn_Gradient_Z(x*_C/_Interations,y*_C/_Interations,z*_C/_Interations)*z
   )/_Interations*2/3
 #end
  +(
   _fn_Gradient_X(x,y,z)*x+
   _fn_Gradient_Y(x,y,z)*y+
   _fn_Gradient_Z(x,y,z)*z
   )/_Interations/3
}
#end //fn_Integradient
/*
//Non simpson method
#macro
fn_Integradient(_fn_Gradient_X,_fn_Gradient_Y,_fn_Gradient_Z,_Interations)

function{0
 #local _C = 0;
 #while(_C<_Interations)
 #local _C = _C+1;
 +(
   _fn_Gradient_X(x*_C/_Interations,y*_C/_Interations,z*_C/_Interations)*x+
   _fn_Gradient_Y(x*_C/_Interations,y*_C/_Interations,z*_C/_Interations)*y+
   _fn_Gradient_Z(x*_C/_Interations,y*_C/_Interations,z*_C/_Interations)*z
   )/_Interations
 #end
}
#end //fn_Integradient
*/


Post a reply to this message

From: JC (Exether)
Subject: Re: Integration of Gradient functions. Fun with gradients :P
Date: 4 Sep 2003 11:41:46
Message: <3f575d3a@news.povray.org>
Cool, stuff but I fear it's a lot of fun the CPU too ...  :-)

JC

Pyry wrote:
> I've been trying to get the inverse function of fn_Gradient_Directional(s)
> and I think I finaly got it and here it is (named it fn_Integradient, just
> copy it to your math.inc and it should work like the rest of the
> Gradient-functions):
> 
> 
> 
> 
> 
> 
> //Inverse of gradient_dir functions as a function by:Pyry Pakkanen
> //_fn_Gradient_X;Y;Z is the vector-function component of the gradient at
> //that point of space
> //_Interations must even(2,4,6,20,100 etc.) It is not checked just in case
> //someone wants to experiment with it :P
> //High _Interations produces more accturate results but will be slower
> //The method(Simpson) used is quite slow and does not always produce wanted
> //results.
> //(for example _fn_Gradient_X = function{y} _fn_Gradient_Y = function{0}
> //creates a gradient in the y direction[wich should be zero] for the result
> //function )
> //anything like 1/x does not work because its infinite at <0,0,0> You'll
> //have to move your gradient functions away from <0,0,0> first and move them
> //back for the final function
> //exapmle of usage:
> /*
> //Sphere with a noisy surface without "bubbles" that noise added to
> //functions usually produces (the gradient of the noise gets higher than the
> //gradient of the function)
> //this is fixed by making the gradient of noise porpotional to the gradient
> //of the function
> #declare TTx =function{x/f_r(x,y,z)*pow(f_noise3d(x*4,y*4,z*4),3)*6};
> #declare TTy =function{y/f_r(x,y,z)*pow(f_noise3d(x*4,y*4+100,z*4),3)*6};
> #declare TTz =function{z/f_r(x,y,z)*pow(f_noise3d(x*4,y*4,z*4+100),3)*6};
> 
> #declare TT = fn_Integradient(TTx,TTy,TTz,40);//quite high _Interations
> //have to be used
> //Now TT(x,y,z)-1 can be used to make an isosurface (it looks like blobby
> //combination of spikes)
> //
> */
> 
> #macro
> fn_Integradient(_fn_Gradient_X,_fn_Gradient_Y,_fn_Gradient_Z,_Interations)
> 
> function{0 //start at zero
>  #local _C = 1;
>   +(
>    _fn_Gradient_X(x/_Interations,y/_Interations,z/_Interations)*x+
>    _fn_Gradient_Y(x/_Interations,y/_Interations,z/_Interations)*y+
>    _fn_Gradient_Z(x/_Interations,y/_Interations,z/_Interations)*z
>    )/_Interations/3
>  #while(_C<_Interations-1)
>  #local _C = _C+1;
>  +(
>    _fn_Gradient_X(x*_C/_Interations,y*_C/_Interations,z*_C/_Interations)*x+
>    _fn_Gradient_Y(x*_C/_Interations,y*_C/_Interations,z*_C/_Interations)*y+
>    _fn_Gradient_Z(x*_C/_Interations,y*_C/_Interations,z*_C/_Interations)*z
>    )/_Interations*4/3
>  #local _C = _C+1;
>  +(
>    _fn_Gradient_X(x*_C/_Interations,y*_C/_Interations,z*_C/_Interations)*x+
>    _fn_Gradient_Y(x*_C/_Interations,y*_C/_Interations,z*_C/_Interations)*y+
>    _fn_Gradient_Z(x*_C/_Interations,y*_C/_Interations,z*_C/_Interations)*z
>    )/_Interations*2/3
>  #end
>   +(
>    _fn_Gradient_X(x,y,z)*x+
>    _fn_Gradient_Y(x,y,z)*y+
>    _fn_Gradient_Z(x,y,z)*z
>    )/_Interations/3
> }
> #end //fn_Integradient
> /*
> //Non simpson method
> #macro
> fn_Integradient(_fn_Gradient_X,_fn_Gradient_Y,_fn_Gradient_Z,_Interations)
> 
> function{0
>  #local _C = 0;
>  #while(_C<_Interations)
>  #local _C = _C+1;
>  +(
>    _fn_Gradient_X(x*_C/_Interations,y*_C/_Interations,z*_C/_Interations)*x+
>    _fn_Gradient_Y(x*_C/_Interations,y*_C/_Interations,z*_C/_Interations)*y+
>    _fn_Gradient_Z(x*_C/_Interations,y*_C/_Interations,z*_C/_Interations)*z
>    )/_Interations
>  #end
> }
> #end //fn_Integradient
> */
> 
> 
> 
> 
>


Post a reply to this message

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