POV-Ray : Newsgroups : povray.binaries.images : Ocean : Re: Ocean Server Time
29 Jun 2024 01:38:22 EDT (-0400)
  Re: Ocean  
From: clipka
Date: 8 Apr 2016 08:24:32
Message: <5707a300$1@news.povray.org>
Am 08.04.2016 um 09:49 schrieb Jaime Vives Piqueres:

>> My instinct would be to avoid the analysis approach, and do sampling
>> on the original function.  That doesn't take a lot of sophisticated
>> math.  I can't even remember the chain rule without looking it up
>> (and the last time I did so was, like, 2005), but I have used
>> sampling to estimate normals on a form based on parametric functions.
>> I did this for the smooth triangles of the elliptical toroids in
>> RoundEdge.  Normals, of course, can be easily converted to slopes.
>>
> 
>   I'm still trying to grasp the concept of "sampling a function"... how
> I would do that? With another function? If someone can please post a
> simple example...

// Base function
#declare Fn = function(x,y) { /* whatever */ }

#declare EPSILON = 1e-6;

// Approximate first derivatives along the x and y axes
#declare Fn1X = function(x,y)
  { (Fn(x+EPSILON,y)-Fn(x-EPSILON,y))/EPSILON }
#declare Fn1Y = function(x,y)
  { (Fn(x,y+EPSILON)-Fn(x,y-EPSILON))/EPSILON }

// Approximate second derivatives along the x and y axes
#declare Fn2X = function(x,y)
  { (Fn1X(x+EPSILON,y)-Fn1X(x-EPSILON,y))/EPSILON }
#declare Fn2Y = function(x,y)
  { (Fn1Y(x,y+EPSILON)-Fn1Y(x,y-EPSILON))/EPSILON }

Note how the first derivative functions effectively "sample" the base
function at two points, and the second derivative functions do the same
for the first derivative functions.

(Also note that this formulation of the second derivative is
inefficient, as it results in sampling the base function four times:
Once at an offset of -2*EPSILON, once at an offset of +2*EPSILON, and
twice at an offset of 0; computing the second derivative directly from
samples of the base function could reduce this to three samples.)

The slope can then be computed from the first derivatives, and the
curvature from the second derivatives, both of which I leave as an
exercise to the reader (academic parlance for "I don't have the patience
to figure it out" ;))


Post a reply to this message

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