POV-Ray : Newsgroups : povray.general : Function performance : Function performance Server Time
29 Jul 2024 12:19:18 EDT (-0400)
  Function performance  
From: David Given
Date: 21 Jul 2011 19:14:39
Message: <4e28b2df$1@news.povray.org>
As part of my Insanely Complicated Tree function, I need to clip some
(x, y, z) coordinates to a sphere of radius r. (I'm going to use it as
an isosurface modifier; I want the effect to value according to phi and
theta but be constant for all r.)

The obvious way to do this is to normalise the vector of (x, y, z) and
then multiply by r, which more or less becomes:

f_normal_x(x, y, z, r) = r * x / f_r(x, y, z)
f_normal_y(x, y, z, r) = r * y / f_r(x, y, z)
f_normal_z(x, y, z, r) = r * z / f_r(x, y, z)

(Possible typos/thinkos owing to posting past midnight...)

Now, I'm going to be using this in a single expression:

result(x, y, z, r) = f_bozo(f_normal_x(x, y, z, r), f_normal_y(x, y, z,
r), f_normal_z(x, y, z, r))

My question is: is Povray intelligent enough to calculate f_r(x, y, z)
once, or will it do it three times? If it's going to do it three times,
are there any clean strategies for optimising the function (or should I
just not worry about it)?

My worry is that calculating common values and then passing them in
makes writing modular functions very hard --- the logic gets spread
across all functions rather than being focused in specific areas. e.g.:

result2(x, y, z, r) = f_bozo(x*r, y*r, z*r)
result1(x, y, z, r, R) = result2(x/R, y/R, z/R, r)
result(x, y, z, r) = result1(x, y, z, r, f_r(x, y, z))

...which is much less easy to read.

-- 
┌─── dg@cowlark.com ─────
http://www.cowlark.com ─────
│
│ "I have a mind like a steel trap. It's rusty and full of dead mice."
│ --- Anonymous, on rasfc


Post a reply to this message

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