POV-Ray : Newsgroups : povray.general : Few tricks : Few tricks Server Time
13 May 2024 04:47:28 EDT (-0400)
  Few tricks  
From: kurtz le pirate
Date: 26 Nov 2023 04:46:56
Message: <65631410$1@news.povray.org>
Hello,

In my current project, I'm doing a lot of calculations using macros and
functions. I need macros that return several values and a rounding
function. I'm sharing my solutions here (which may already be known to
the Grand Masters).



*** Tips 1 : Rounding ***

#declare pow10 = function(num_digits) {
  prod(i,1,num_digits,10)
  }
#declare fnRound = function (number, num_digits) {
  ceil(number*pow10(num_digits))/pow10(num_digits)
  }

#declare a = fnRound(pi,6); // round pi to 6 digits
#debug concat(str(a,0,9),"\n")

-> 3.141 593 000 (extra spaces added)

Waring : Be careful with the number of digits required, depending on the
precision of the calculations... especially with large numbers.




*** Tips 2 : Multiple return values from macro directly assigned to
variables ***


#declare MyMacro(p1, p2, p3, p4)
  ..
  ..
  array { Return1, Return2, Return3}
#end


Used in this way :
#declare { V1, V2, V3 } = MyMacro (a, b, c, d);



I hope this helps.
Critical comments welcome !
-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message

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