|
|
On 7/28/2018 3:18 PM, Tor Olav Kristensen wrote:
> "And" <49341109@ntnu.edu.tw> wrote:
>> ...
>> #local h=0.00001;
>> #local normalized_function =
>> function(var1,var2,var3)
>> {
>> input_function(var1,var2,var3)
>> /sqrt(
>> pow((input_function(var1+h,var2,var3)-input_function(var1,var2,var3))/h,2)
>> +pow((input_function(var1,var2+h,var3)-input_function(var1,var2,var3))/h,2)
>> +pow((input_function(var1,var2,var3+h)-input_function(var1,var2,var3))/h,2)
>> )
>> }
>> ...
>
> And, there is a macro in math.inc that can create the gradient function for your
> denominator: fn_Gradient()
>
> Here's how you can use it:
>
> #include "math.inc"
>
> SetGradientAccuracy(h)
> #local GradientFn = fn_Gradient(input_function)
> #local normalized_function =
> function { input_function(x, y, z)/GradientFn(x, y, z) }
>
>
> I suspect that this will be a little faster, since fn_Gradient() uses f_r()
> instead of sqrt() and pow() and since the division by h (or 2*h in fn_Gradient)
> is moved outside.
>
> Here's the relevant documentation pages:
> http://www.povray.org/documentation/view/3.6.1/460/
> http://www.povray.org/documentation/3.7.0/r3_4.html#r3_4_9_1_12_3
>
> --
> Tor Olav
> http://subcube.com
>
>
>
I am using these functions:
#declare f_test = function(var1,var2,var3,varA,varB,varC)
{pow(var1,2)+pow(var2,2)+pow(var3,2)-1-0.5*f_noise3d(var1*varA,var2*varB,var3*varC)}
#declare f_normalized = function(var1,var2,var3,varA,varB,varC)
{f_test(var1,var2,var3,varA,varB,varC)/sqrt(4*pow(var1,2)/pow(varA,4)+4*pow(var2,2)/pow(varB,4)+4*pow(var3,2)/pow(varC,4))}
How would I rewrite them using fn_Gradient()?
Thanks.
Post a reply to this message
|
|