POV-Ray : Newsgroups : povray.programming : cycloidal()? : cycloidal()? Server Time
26 Apr 2024 07:21:09 EDT (-0400)
  cycloidal()?  
From: Christopher James Huff
Date: 6 Jan 2005 22:32:43
Message: <cjameshuff-9CA1F9.22323806012005@news.povray.org>
Could someone explain the construction of this function to me? (Found in 
texture.cpp)

DBL cycloidal(DBL value)
{
  if (value >= 0.0)
  {
        return sin((DBL) (((value - floor(value)) * 50000.0)) / 50000.0 
* TWO_M_PI)  ;
  }
  else
  {
        return 0.0-sin((DBL) (((0.0 - (value + floor(0.0 - value))) * 
50000.0)) / 50000.0 * TWO_M_PI);
  }
}

Is there some point to multiplying the value by 50000 and then dividing 
it by the same value?
And then, for negative values, it does weird things to the input to 
sin() and then negates the result...

The two expressions simplify to:
sin((value - floor(value)) * TWO_M_PI)
and:
sin((value + floor(-value)) * TWO_M_PI)

So, near as I can tell, the function does the same thing as this:

DBL cycloidal(DBL value)
{
    return sin(fmod(value, 1)*TWO_M_PI);
}

So...why? Why all the code to avoid the fmod() function, and why that 
weird multiplication and division above?

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

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