libnoise logo

A portable, open-source, coherent noise-generating library for C++


interp.h

00001 // interp.h
00002 //
00003 // Copyright (C) 2003, 2004 Jason Bevins
00004 //
00005 // This library is free software; you can redistribute it and/or modify it
00006 // under the terms of the GNU Lesser General Public License as published by
00007 // the Free Software Foundation; either version 2.1 of the License, or (at
00008 // your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful, but WITHOUT
00011 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00013 // License (COPYING.txt) for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this library; if not, write to the Free Software Foundation,
00017 // Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //
00019 // The developer's email is jlbezigvins@gmzigail.com (for great email, take
00020 // off every 'zig'.)
00021 //
00022 
00023 #ifndef NOISE_INTERP_H
00024 #define NOISE_INTERP_H
00025 
00026 namespace noise
00027 {
00028 
00031 
00046   inline double CubicInterp (double n0, double n1, double n2, double n3,
00047     double a)
00048   {
00049     double p = (n3 - n2) - (n0 - n1);
00050     double q = (n0 - n1) - p;
00051     double r = n2 - n0;
00052     double s = n1;
00053     return p * a * a * a + q * a * a + r * a + s;
00054   }
00055 
00067   inline double LinearInterp (double n0, double n1, double a)
00068   {
00069     return ((1.0 - a) * n0) + (a * n1);
00070   }
00071 
00082   inline double SCurve3 (double a)
00083   {
00084     return (a * a * (3.0 - 2.0 * a));
00085   }
00086 
00100   inline double SCurve5 (double a)
00101   {
00102     double a3 = a * a * a;
00103     double a4 = a3 * a;
00104     double a5 = a4 * a;
00105     return (6.0 * a5) - (15.0 * a4) + (10.0 * a3);
00106   }
00107 
00108   // @}
00109 
00110 }
00111 
00112 #endif