POV-Ray : Newsgroups : povray.advanced-users : modulo / math funktions : Re: modulo / math funktions Server Time
29 Jul 2024 22:26:03 EDT (-0400)
  Re: modulo / math funktions  
From: Ron Parker
Date: 30 Oct 2001 10:16:46
Message: <slrn9tth2v.n0q.ron.parker@fwi.com>
On Tue, 30 Oct 2001 09:44:11 -0500, Dave Dunn wrote:
> 
> 
> Slime wrote:
> 
>> >   "How do I calculate the normal vector of an isosurface function at a
>> > certain point <x,y,z>?", for example.
>>
>> Now *there's* a question that's been plaguing me for a while. I'll ask it
>> later. =)
> 
> I'll be watching for the answer to that one myself, as it is holding up
> isosurface support for POVGUI. I suspect it involves using trace...

Well, if you know how to take the derivative of the function, you just use
the gradient vector, which is < df/dx, df/dy, df/dz > where "d" is really 
the lowercase delta we use to indicate partial derivatives.

Since we're talking about arbitrary functions here, you can approximate the
gradient by using this:

#declare d = 1e-5; //(some small number; POV uses the accuracy value)
#declare Gradient=vnormalize(<F(X+d,Y,Z),F(X,Y+d,Z),F(X,Y,Z+d)>-F(X,Y,Z));

This is what POV does.  As the comment says, we use the value you specified
for the accuracy of the isosurface to do the computation.  Notice that this
does not work properly for functions with zero gradients; you should detect
that and deal with it appropriately.

--
#macro R(L P)sphere{L __}cylinder{L P __}#end#macro P(_1)union{R(z+_ z)R(-z _-z)
R(_-z*3_+z)torus{1__ clipped_by{plane{_ 0}}}translate z+_1}#end#macro S(_)9-(_1-
_)*(_1-_)#end#macro Z(_1 _ __)union{P(_)P(-_)R(y-z-1_)translate.1*_1-y*8pigment{
rgb<S(7)S(5)S(3)>}}#if(_1)Z(_1-__,_,__)#end#end Z(10x*-2,.2)camera{rotate x*90}


Post a reply to this message

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