| 1 | /****************************************************************************/cxx . . $ `<file>/src/medit/cenrad.c`/ |
| 2 | /* This file is part of FreeFEM. */ |
| 3 | /* */ |
| 4 | /* FreeFEM is free software: you can redistribute it and/or modify */ |
| 5 | /* it under the terms of the GNU Lesser General Public License as */ |
| 6 | /* published by the Free Software Foundation, either version 3 of */ |
| 7 | /* the License, or (at your option) any later version. */ |
| 8 | /* */ |
| 9 | /* FreeFEM 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 Lesser General Public License for more details. */ |
| 13 | /* */ |
| 14 | /* You should have received a copy of the GNU Lesser General Public License */ |
| 15 | /* along with FreeFEM. If not, see <http://www.gnu.org/licenses/>. */ |
| 16 | /****************************************************************************/ |
| 17 | /* SUMMARY : ... */ |
| 18 | /* LICENSE : LGPLv3 */ |
| 19 | /* ORG : LJLL Universite Pierre et Marie Curie, Paris, FRANCE */ |
| 20 | /* AUTHORS : Pascal Frey */ |
| 21 | /* E-MAIL : [email protected] */ |
| 22 | |
| 23 | #ifdef __cplusplus |
| 24 | extern "C" { |
| 25 | #endif |
| 26 | |
| 27 | #include <stdio.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <math.h> |
| 30 | |
| 31 | #include "medit.h"cxx . . $ `<file>/src/medit/medit.h`/ |
| 32 | #include "extern.h"cxx . . $ `<file>/src/medit/extern.h`/ |
| 33 | #include "sproto.h"cxx . . $ `<file>/src/medit/sproto.h`/ |
| 34 | |
| 35 | /* compute circumradius and center */ |
| 36 | int cenradcxx . . $ cenrad(5a3b08c96b63088b).(pMeshcxx . . $ pMesh# mesh, int iel, double *c, double *rad) { |
| 37 | pTetracxx . . $ pTetra# pt; |
| 38 | pPointcxx . . $ pPoint# p1, p2, p3, p4; |
| 39 | double dd, ux, uy, uz, n1[3], n2[3], n3[3], c1, c2, c3, pl1, pl2, pl3; |
| 40 | |
| 41 | pt = &mesh->tetracxx . . $ mesh#tetra.[iel]; |
| 42 | if (!pt->vcxx . . $ stetra#v.[0]) return (0); |
| 43 | |
| 44 | p1 = &mesh->pointcxx . . $ mesh#point.[pt->vcxx . . $ stetra#v.[0]]; |
| 45 | p2 = &mesh->pointcxx . . $ mesh#point.[pt->vcxx . . $ stetra#v.[1]]; |
| 46 | p3 = &mesh->pointcxx . . $ mesh#point.[pt->vcxx . . $ stetra#v.[2]]; |
| 47 | p4 = &mesh->pointcxx . . $ mesh#point.[pt->vcxx . . $ stetra#v.[3]]; |
| 48 | |
| 49 | ux = p4->ccxx . . $ spoint#c.[0] - p1->ccxx . . $ spoint#c.[0]; |
| 50 | uy = p4->ccxx . . $ spoint#c.[1] - p1->ccxx . . $ spoint#c.[1]; |
| 51 | uz = p4->ccxx . . $ spoint#c.[2] - p1->ccxx . . $ spoint#c.[2]; |
| 52 | dd = 1.0 / sqrt(ux * ux + uy * uy + uz * uz); |
| 53 | n1[0] = ux * dd; |
| 54 | n1[1] = uy * dd; |
| 55 | n1[2] = uz * dd; |
| 56 | /* plan: vecteur directeur passant par milieu(1,4) */ |
| 57 | pl1 = |
| 58 | n1[0] * (p4->ccxx . . $ spoint#c.[0] + p1->ccxx . . $ spoint#c.[0]) + n1[1] * (p4->ccxx . . $ spoint#c.[1] + p1->ccxx . . $ spoint#c.[1]) + n1[2] * (p4->ccxx . . $ spoint#c.[2] + p1->ccxx . . $ spoint#c.[2]); |
| 59 | |
| 60 | ux = p4->ccxx . . $ spoint#c.[0] - p2->ccxx . . $ spoint#c.[0]; |
| 61 | uy = p4->ccxx . . $ spoint#c.[1] - p2->ccxx . . $ spoint#c.[1]; |
| 62 | uz = p4->ccxx . . $ spoint#c.[2] - p2->ccxx . . $ spoint#c.[2]; |
| 63 | dd = 1.0 / sqrt(ux * ux + uy * uy + uz * uz); |
| 64 | n2[0] = ux * dd; |
| 65 | n2[1] = uy * dd; |
| 66 | n2[2] = uz * dd; |
| 67 | pl2 = |
| 68 | n2[0] * (p4->ccxx . . $ spoint#c.[0] + p2->ccxx . . $ spoint#c.[0]) + n2[1] * (p4->ccxx . . $ spoint#c.[1] + p2->ccxx . . $ spoint#c.[1]) + n2[2] * (p4->ccxx . . $ spoint#c.[2] + p2->ccxx . . $ spoint#c.[2]); |
| 69 | |
| 70 | ux = p4->ccxx . . $ spoint#c.[0] - p3->ccxx . . $ spoint#c.[0]; |
| 71 | uy = p4->ccxx . . $ spoint#c.[1] - p3->ccxx . . $ spoint#c.[1]; |
| 72 | uz = p4->ccxx . . $ spoint#c.[2] - p3->ccxx . . $ spoint#c.[2]; |
| 73 | dd = 1.0 / sqrt(ux * ux + uy * uy + uz * uz); |
| 74 | n3[0] = ux * dd; |
| 75 | n3[1] = uy * dd; |
| 76 | n3[2] = uz * dd; |
| 77 | pl3 = |
| 78 | n3[0] * (p4->ccxx . . $ spoint#c.[0] + p3->ccxx . . $ spoint#c.[0]) + n3[1] * (p4->ccxx . . $ spoint#c.[1] + p3->ccxx . . $ spoint#c.[1]) + n3[2] * (p4->ccxx . . $ spoint#c.[2] + p3->ccxx . . $ spoint#c.[2]); |
| 79 | |
| 80 | /* center = intersection of 3 planes */ |
| 81 | ux = n2[1] * n3[2] - n2[2] * n3[1]; |
| 82 | uy = n1[2] * n3[1] - n1[1] * n3[2]; |
| 83 | uz = n1[1] * n2[2] - n1[2] * n2[1]; |
| 84 | |
| 85 | dd = n1[0] * ux + n2[0] * uy + n3[0] * uz; |
| 86 | dd = 0.5 / dd; |
| 87 | |
| 88 | c1 = ux * pl1 + uy * pl2 + uz * pl3; |
| 89 | c2 = pl1 * (n2[2] * n3[0] - n2[0] * n3[2]) + pl2 * (n1[0] * n3[2] - n3[0] * n1[2]) + |
| 90 | pl3 * (n2[0] * n1[2] - n2[2] * n1[0]); |
| 91 | c3 = pl1 * (n2[0] * n3[1] - n2[1] * n3[0]) + pl2 * (n3[0] * n1[1] - n3[1] * n1[0]) + |
| 92 | pl3 * (n1[0] * n2[1] - n2[0] * n1[1]); |
| 93 | |
| 94 | c[0] = dd * c1; |
| 95 | c[1] = dd * c2; |
| 96 | c[2] = dd * c3; |
| 97 | |
| 98 | /* radius (squared) */ |
| 99 | *rad = (c[0] - p4->ccxx . . $ spoint#c.[0]) * (c[0] - p4->ccxx . . $ spoint#c.[0]) + (c[1] - p4->ccxx . . $ spoint#c.[1]) * (c[1] - p4->ccxx . . $ spoint#c.[1]) + |
| 100 | (c[2] - p4->ccxx . . $ spoint#c.[2]) * (c[2] - p4->ccxx . . $ spoint#c.[2]); |
| 101 | |
| 102 | return (1); |
| 103 | } |
| 104 | |
| 105 | #ifdef __cplusplus |
| 106 | } |
| 107 | #endif |