1 /**************************************************************************/ 2 /* Copyright 2012 Tim Day */ 3 /* */ 4 /* This file is part of Evolvotron */ 5 /* */ 6 /* Evolvotron is free software: you can redistribute it and/or modify */ 7 /* it under the terms of the GNU General Public License as published by */ 8 /* the Free Software Foundation, either version 3 of the License, or */ 9 /* (at your option) any later version. */ 10 /* */ 11 /* Evolvotron is distributed in the hope that it will be useful, */ 12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ 14 /* GNU General Public License for more details. */ 15 /* */ 16 /* You should have received a copy of the GNU General Public License */ 17 /* along with Evolvotron. If not, see <http://www.gnu.org/licenses/>. */ 18 /**************************************************************************/ 19 20 /*! \file 21 \brief Interfaces and implementation for specific Function classes. 22 As much as possible of the implementation should be pushed into the FunctionBoilerplate template. 23 */ 24 25 #ifndef _functions_kaleidoscope_h_ 26 #define _functions_kaleidoscope_h_ 27 28 #include "common.h" 29 30 #include "function_boilerplate.h" 31 32 //------------------------------------------------------------------------------------------ 33 34 //! Implements reflection of sampling point about multiple planes 35 FUNCTION_BEGIN(FunctionKaleidoscope,1,1,false,FnStructure) 36 37 //! Evaluate function. evaluate(const XYZ & p)38 virtual const XYZ evaluate(const XYZ& p) const 39 { 40 const uint n=2+static_cast<uint>(floor(8.0*fabs(param(0)))); 41 42 const real a=atan2(p.x(),p.y()); 43 const real r=sqrt(p.x()*p.x()+p.y()*p.y()); 44 45 const real sa=trianglef(a,M_PI/n); 46 47 const XYZ s(r*sin(sa),r*cos(sa),p.z()); 48 return arg(0)(s); 49 } 50 51 FUNCTION_END(FunctionKaleidoscope) 52 53 //------------------------------------------------------------------------------------------ 54 55 //! Like FunctionKaleidoscope but Z drives rotation of underlying function 56 /*! Good for animation 57 */ 58 FUNCTION_BEGIN(FunctionKaleidoscopeZRotate,2,1,false,FnStructure) 59 60 //! Evaluate function. evaluate(const XYZ & p)61 virtual const XYZ evaluate(const XYZ& p) const 62 { 63 const uint n=2+static_cast<uint>(floor(8.0*fabs(param(0)))); 64 65 const real a=atan2(p.x(),p.y()); 66 const real r=sqrt(p.x()*p.x()+p.y()*p.y()); 67 68 const real sa=trianglef(a,M_PI/n)+param(1)*p.z(); 69 70 const XYZ s(r*sin(sa),r*cos(sa),0.0); 71 return arg(0)(s); 72 } 73 74 FUNCTION_END(FunctionKaleidoscopeZRotate) 75 76 //------------------------------------------------------------------------------------------ 77 78 //! Like FunctionKaleidoscope with a twist 79 FUNCTION_BEGIN(FunctionKaleidoscopeTwist,2,1,false,FnStructure) 80 81 //! Evaluate function. evaluate(const XYZ & p)82 virtual const XYZ evaluate(const XYZ& p) const 83 { 84 const uint n=2+static_cast<uint>(floor(8.0*fabs(param(0)))); 85 86 const real a=atan2(p.x(),p.y()); 87 const real r=sqrt(p.x()*p.x()+p.y()*p.y()); 88 89 const real sa=trianglef(a-r*param(1),M_PI/n); 90 91 const XYZ s(r*sin(sa),r*cos(sa),p.z()); 92 return arg(0)(s); 93 } 94 95 FUNCTION_END(FunctionKaleidoscopeTwist) 96 97 //------------------------------------------------------------------------------------------ 98 99 //! Implements reflection of sampling point about multiple planes 100 FUNCTION_BEGIN(FunctionWindmill,1,1,false,FnStructure) 101 102 //! Evaluate function. evaluate(const XYZ & p)103 virtual const XYZ evaluate(const XYZ& p) const 104 { 105 const uint n=1+static_cast<uint>(floor(8.0*fabs(param(0)))); 106 107 const real a=atan2(p.x(),p.y()); 108 const real r=sqrt(p.x()*p.x()+p.y()*p.y()); 109 110 const real sa=modulusf(a,M_PI/n); 111 112 const XYZ s(r*sin(sa),r*cos(sa),p.z()); 113 return arg(0)(s); 114 } 115 116 FUNCTION_END(FunctionWindmill) 117 118 //------------------------------------------------------------------------------------------ 119 120 //! Like FunctionWindmill but Z drives rotation of underlying function 121 /*! Good for animation 122 */ 123 FUNCTION_BEGIN(FunctionWindmillZRotate,2,1,false,FnStructure) 124 125 //! Evaluate function. evaluate(const XYZ & p)126 virtual const XYZ evaluate(const XYZ& p) const 127 { 128 const uint n=1+static_cast<uint>(floor(8.0*fabs(param(0)))); 129 130 const real a=atan2(p.x(),p.y()); 131 const real r=sqrt(p.x()*p.x()+p.y()*p.y()); 132 133 const real sa=modulusf(a,M_PI/n)+param(1)*p.z(); 134 135 const XYZ s(r*sin(sa),r*cos(sa),0.0); 136 return arg(0)(s); 137 } 138 139 FUNCTION_END(FunctionWindmillZRotate) 140 141 //------------------------------------------------------------------------------------------ 142 143 //! Like FunctionWindmill with twist 144 FUNCTION_BEGIN(FunctionWindmillTwist,2,1,false,FnStructure) 145 146 //! Evaluate function. evaluate(const XYZ & p)147 virtual const XYZ evaluate(const XYZ& p) const 148 { 149 const uint n=1+static_cast<uint>(floor(8.0*fabs(param(0)))); 150 151 const real a=atan2(p.x(),p.y()); 152 const real r=sqrt(p.x()*p.x()+p.y()*p.y()); 153 154 const real sa=modulusf(a-r*param(1),M_PI/n); 155 156 const XYZ s(r*sin(sa),r*cos(sa),p.z()); 157 return arg(0)(s); 158 } 159 160 FUNCTION_END(FunctionWindmillTwist) 161 162 //------------------------------------------------------------------------------------------ 163 164 #endif 165