LevelS C++ support library  3.83
geom_utils.cc
1 /*
2  * This file is part of libcxxsupport.
3  *
4  * libcxxsupport 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 2 of the License, or
7  * (at your option) any later version.
8  *
9  * libcxxsupport 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 libcxxsupport; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /*
20  * libcxxsupport is being developed at the Max-Planck-Institut fuer Astrophysik
21  * and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
22  * (DLR).
23  */
24 
25 /*
26  * Copyright (C) 2011-2016 Max-Planck-Society
27  * \author Martin Reinecke
28  */
29 
30 #include "geom_utils.h"
31 
32 using namespace std;
33 
34 namespace {
35 
36 void get_circle (const vector<vec3> &point, tsize q1, tsize q2, vec3 &center,
37  double &cosrad)
38  {
39  center = (point[q1]+point[q2]).Norm();
40  cosrad = dotprod(point[q1],center);
41  for (tsize i=0; i<q1; ++i)
42  if (dotprod(point[i],center)<cosrad) // point outside the current circle
43  {
44  center=crossprod(point[q1]-point[i],point[q2]-point[i]).Norm();
45  cosrad=dotprod(point[i],center);
46  if (cosrad<0)
47  { center.Flip(); cosrad=-cosrad; }
48  }
49  }
50 void get_circle (const vector<vec3> &point, tsize q, vec3 &center,
51  double &cosrad)
52  {
53  center = (point[0]+point[q]).Norm();
54  cosrad = dotprod(point[0],center);
55  for (tsize i=1; i<q; ++i)
56  if (dotprod(point[i],center)<cosrad) // point outside the current circle
57  get_circle(point,i,q,center,cosrad);
58  }
59 
60 } // unnamed namespace
61 
62 void find_enclosing_circle (const vector<vec3> &point, vec3 &center,
63  double &cosrad)
64  {
65  tsize np=point.size();
66  planck_assert(np>=2,"too few points");
67  center = (point[0]+point[1]).Norm();
68  cosrad = dotprod(point[0],center);
69  for (tsize i=2; i<np; ++i)
70  if (dotprod(point[i],center)<cosrad) // point outside the current circle
71  get_circle(point,i,center,cosrad);
72  }
void Flip()
Definition: vec3.h:97
std::size_t tsize
Definition: datatypes.h:116
void find_enclosing_circle(const std::vector< vec3 > &point, vec3 &center, double &cosrad)
Definition: vec3.h:43
#define planck_assert(testval, msg)

Generated on Wed Nov 13 2024 12:18:16 for LevelS C++ support library