PLaSK library

Loading...
Searching...
No Matches
interpolation.hpp
Go to the documentation of this file.
1/*
2 * This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3 * Copyright (c) 2022 Lodz University of Technology
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14#ifndef PLASK__UTILS_INTERPOLATION_H
15#define PLASK__UTILS_INTERPOLATION_H
16
21 namespace plask { namespace interpolation {
22
30 template <typename T>
31 inline T linear(double p_lo, const T& d_lo, double p_hi, const T& d_hi, double p) {
32 //return ((p_hi - p) * d_lo + (p - p_lo) * d_hi) / (p_hi - p_lo);
33 return d_lo + (p - p_lo) / (p_hi - p_lo) * (d_hi - d_lo);
34 }
35
43 template <typename T>
44 inline T bilinear(double p_l, double p_r, double p_b, double p_t,
45 const T& d_lb, const T& d_rb, const T& d_rt, const T& d_lt,
46 double p_x, double p_y) {
47 const double delta_x_hi = p_r - p_x;
48 const double delta_x_lo = p_x - p_l;
49 return ((d_lb * delta_x_hi + d_rb * delta_x_lo) * (p_t - p_y) +
50 (d_lt * delta_x_hi + d_rt * delta_x_lo) * (p_y - p_b))
51 / (p_t - p_b) / (p_r - p_l);
52 }
53
63 template <typename T>
64 inline T trilinear(double p_l, double p_r, double p_b, double p_t, double p_lo, double p_hi,
65 const T& lo_d_lb, const T& lo_d_rb, const T& lo_d_rt, const T& lo_d_lt,
66 const T& hi_d_lb, const T& hi_d_rb, const T& hi_d_rt, const T& hi_d_lt,
67 double p_x, double p_y, double p_lohi) {
68 return linear(p_lo, bilinear(p_l, p_r, p_b, p_t, lo_d_lb, lo_d_rb, lo_d_rt, lo_d_lt, p_x, p_y),
69 p_hi, bilinear(p_l, p_r, p_b, p_t, hi_d_lb, hi_d_rb, hi_d_rt, hi_d_lt, p_x, p_y),
70 p_lohi);
71 }
72
73} }
74
75#endif // PLASK__UTILS_INTERPOLATION_H