POV-Ray : Newsgroups : povray.general : Roots of a function : Re: Roots of a function Server Time
19 Apr 2024 02:07:09 EDT (-0400)
  Re: Roots of a function  
From: Alain Martel
Date: 30 Sep 2019 18:58:13
Message: <5d928885@news.povray.org>
Le 2019-09-29 à 03:07, IGM a écrit :
> This is my poor-man solution:
> 
> // root(s) of function F = Y(X)-thr
> // Example:
> // #declare X = array [10] {0,10,20,30,40,50,60,70,80,90};
> // #declare C = array [10]
> {0.000,21.000,44.000,69.000,97.000,124.000,158.000,181.000,206.000,232.000};
> // root(X,C,35)
> // #debug concat("root: ", str(macro_value,5,3),"\n")
> #macro root(X,Y,thr)
> 
>      #include "math.inc"
>      GetStats(Y);
> 
>      #local f_prism = prism {
>          linear_spline
>          -1, 1, dimension_size(Y,1)+3,
> 
>          #for (k,0,dimension_size(Y,1)-1)
>              <X[k],Y[k]>,
>          #end
>          <X[dimension_size(Y,1)-1],StatisticsArray[2]-1>, // add lower point 1
>          <X[0],StatisticsArray[2]-1>, // add lower point 2
>          <X[0],Y[0]> // close prism
>          // rotate x*-90 // For plot in x,z plane. In this case P0 = <0,thr,0>
>          }
> 
>      #object {f_prism pigment {rgb <0,2,0>} } // no_image?
> 
>      #local P0 = <0,0,thr>; // Starting point
>      #local V0 = <1,0,0>; // Incident vector
>      // Trace to object
>      #local N = <99,99,99>; // init
>      #local P1 = trace(f_prism, P0, V0, N); // Loop here to find multiple roots
>      // Plot traced ray:
>      // #cylinder {P0, P1, 1 pigment {rgb <0,1,0>} no_shadow no_reflection}
> 
>      // For multiple roots create array!
>      #declare macro_value = P1.x;
> #end
> 
> 

Why that «#» in front of «object» and that other one in front of 
«cylinder» ?

The «#» is needed in front of directives, never in front of a primitive.

It should be :
object {f_prism pigment {rgb <0,2,0>} }

and
cylinder {P0, P1, 1 pigment {rgb <0,1,0>} no_shadow no_reflection}


Post a reply to this message

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