test_ssol_circ2D_geometry.h (1832B)
1 /* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) 2 * Copyright (C) 2016, 2018 CNRS 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 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 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 17 #include "test_ssol_geometries.h" 18 #include <rsys/math.h> 19 20 21 /******************************************************************************* 22 * Circle polygon 23 ******************************************************************************/ 24 #if !defined(RADIUS) 25 #error "Missing the RADIUS macro defining the circle radius" 26 #endif 27 #if !defined(NVERTS) 28 #define NVERTS 36 29 #endif 30 #if !defined(CIRCLE_NAME) 31 #error "Missing the CIRCLE_NAME macro defining the circle name" 32 #endif 33 34 #define EDGES__ CONCAT(CIRCLE_NAME, _EDGES__) 35 #define INIT_FUNC__ CONCAT(init_, CIRCLE_NAME) 36 37 /* should be const but scpr expects non-const data */ 38 static double EDGES__ [2*NVERTS]; 39 40 static void INIT_FUNC__() { 41 int n; 42 /* radius that give the same area than a circle */ 43 double r = sqrt(2 * RADIUS * RADIUS * PI / (sin(2 * PI / NVERTS) * NVERTS)); 44 for (n = 0; n < NVERTS; n++) { 45 EDGES__[2 * n] = r * cos((double)-n * 2 * PI / (double)NVERTS); 46 EDGES__[2 * n + 1] = r * sin((double)-n * 2 * PI / (double) NVERTS); 47 } 48 } 49 50 #undef EDGES__ 51 #undef INIT_FUNC__ 52 53 #undef RADIUS 54 #undef NVERTS 55 #undef CIRCLE_NAME