Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
constructions/kernel_ftC2.h
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // Copyright (c) 2000 The CGAL Consortium
4 
5 // This software and related documentation is part of the Computational
6 // Geometry Algorithms Library (CGAL).
7 // This software and documentation is provided "as-is" and without warranty
8 // of any kind. In no event shall the CGAL Consortium be liable for any
9 // damage of any kind.
10 //
11 // Every use of CGAL requires a license.
12 //
13 // Academic research and teaching license
14 // - For academic research and teaching purposes, permission to use and copy
15 // the software and its documentation is hereby granted free of charge,
16 // provided that it is not a component of a commercial product, and this
17 // notice appears in all copies of the software and related documentation.
18 //
19 // Commercial licenses
20 // - A commercial license is available through Algorithmic Solutions, who also
21 // markets LEDA (http://www.algorithmic-solutions.de).
22 // - Commercial users may apply for an evaluation license by writing to
23 // Algorithmic Solutions (contact@algorithmic-solutions.com).
24 //
25 // The CGAL Consortium consists of Utrecht University (The Netherlands),
26 // ETH Zurich (Switzerland), Free University of Berlin (Germany),
27 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg
28 // (Germany), Max-Planck-Institute Saarbrucken (Germany), RISC Linz (Austria),
29 // and Tel-Aviv University (Israel).
30 //
31 // ----------------------------------------------------------------------
32 //
33 // release : CGAL-2.2
34 // release_date : 2000, September 30
35 //
36 // file : include/CGAL/constructions/kernel_ftC2.h
37 // package : C2 (4.4)
38 // revision : $Revision: 1.1.1.1 $
39 // revision_date : $Date: 2001/07/05 22:17:49 $
40 // author(s) : Sven Schoenherr, Hervé Brönnimann, Sylvain Pion
41 // coordinator : INRIA Sophia-Antipolis
42 //
43 // email : contact@cgal.org
44 // www : http://www.cgal.org
45 //
46 // ======================================================================
47 
48 #ifndef CGAL_CONSTRUCTIONS_KERNEL_FTC2_H
49 #define CGAL_CONSTRUCTIONS_KERNEL_FTC2_H
50 
51 #include <CGAL/determinant.h>
52 
54 
55 template < class FT >
57 void
58 midpointC2( const FT &px, const FT &py,
59  const FT &qx, const FT &qy,
60  FT &x, FT &y )
61 {
62  x = (px+qx) / FT(2);
63  y = (py+qy) / FT(2);
64 }
65 
66 template < class FT >
68 void
69 circumcenter_translateC2(const FT &dqx, const FT &dqy,
70  const FT &drx, const FT &dry,
71  FT &dcx, FT &dcy)
72 {
73  // Given 3 points P, Q, R, this function takes as input:
74  // qx-px, qy-py, rx-px, ry-py. And returns cx-px, cy-py,
75  // where (cx, cy) are the coordinates of the circumcenter C.
76 
77  // What we do is intersect the bisectors.
78  FT r2 = CGAL_NTS square(drx) + CGAL_NTS square(dry);
79  FT q2 = CGAL_NTS square(dqx) + CGAL_NTS square(dqy);
80  FT den = FT(2) * det2x2_by_formula(dqx, dqy, drx, dry);
81 
82  // The 3 points aren't collinear.
83  // Hopefully, this is already checked at the upper level.
84  CGAL_kernel_assertion ( den != FT(0) );
85 
86  // One possible optimization here is to precompute 1/den, to avoid one
87  // division. However, we loose precision, and it's maybe not worth it (?).
88  dcx = det2x2_by_formula (dry, dqy, r2, q2) / den;
89  dcy = - det2x2_by_formula (drx, dqx, r2, q2) / den;
90 }
91 
92 template < class FT >
94 void
95 circumcenterC2( const FT &px, const FT &py,
96  const FT &qx, const FT &qy,
97  const FT &rx, const FT &ry,
98  FT &x, FT &y )
99 {
100  circumcenter_translateC2(qx-px, qy-py, rx-px, ry-py, x, y);
101  x += px;
102  y += py;
103 }
104 
105 template < class FT >
106 inline
107 void
108 line_from_pointsC2(const FT &px, const FT &py,
109  const FT &qx, const FT &qy,
110  FT &a, FT &b, FT &c)
111 {
112  a = py - qy;
113  b = qx - px;
114  // Suggested by Serge Pashkov (psw@rt.kiam.ru) for better numeric stability.
115  c = -px*a - py*b;
116  // c = px*qy - py*qx;
117 }
118 
119 template < class FT >
120 inline
121 void
122 line_from_point_directionC2(const FT &px, const FT &py,
123  const FT &dx, const FT &dy,
124  FT &a, FT &b, FT &c)
125 {
126  a = - dy;
127  b = dx;
128  c = px*dy - py*dx;
129 }
130 
131 template < class FT >
133 void
134 bisector_of_pointsC2(const FT &px, const FT &py,
135  const FT &qx, const FT &qy,
136  FT &a, FT &b, FT& c )
137 {
138  a = FT(2)*(px - qx);
139  b = FT(2)*(py - qy);
140  c = CGAL_NTS square(qx) + CGAL_NTS square(qy) -
141  CGAL_NTS square(px) - CGAL_NTS square(py);
142 }
143 
144 template < class FT >
145 inline
146 FT
147 line_y_at_xC2(const FT &a, const FT &b, const FT &c, const FT &x)
148 {
149  return (-a*x-c) / b;
150 }
151 
152 template < class FT >
153 inline
154 void
155 line_get_pointC2(const FT &a, const FT &b, const FT &c, int i,
156  FT &x, FT &y)
157 {
158  if (b==FT(0))
159  {
160  x = (-b-c)/a + FT(i)*b;
161  y = FT(1) - FT(i)*a;
162  }
163  else
164  {
165  x = FT(1) + FT(i)*b;
166  y = -(a+c)/b - FT(i)*a;
167  }
168 }
169 
170 template < class FT >
171 inline
172 void
173 perpendicular_through_pointC2(const FT &la, const FT &lb,
174  const FT &px, const FT &py,
175  FT &a, FT &b, FT &c)
176 {
177  a = -lb;
178  b = la;
179  c = lb * px - la * py;
180 }
181 
182 template < class FT >
184 void
185 line_project_pointC2(const FT &la, const FT &lb, const FT &lc,
186  const FT &px, const FT &py,
187  FT &x, FT &y)
188 {
189 #if 1
190  // Original old version
191  if (la==FT(0)) // horizontal line
192  {
193  x = px;
194  y = -lc/lb;
195  }
196  else if (lb==FT(0)) // vertical line
197  {
198  x = -lc/la;
199  y = py;
200  }
201  else
202  {
203  FT ab = la/lb, ba = lb/la, ca = lc/la;
204  y = ( -px + ab*py - ca ) / ( ba + ab );
205  x = -ba * y - ca;
206  }
207 #else
208  // New version, with more multiplications, but less divisions and tests.
209  // Let's compare the results of the 2, benchmark them, as well as check
210  // the precision with the intervals.
211  FT a2 = CGAL_NTS square(la);
212  FT b2 = CGAL_NTS square(lb);
213  FT d = a2 + b2;
214  x = (la * (lb * py - lc) - px * b2) / d;
215  y = (lb * (lc - la * px) + py * a2) / d;
216 #endif
217 }
218 
219 template < class FT >
221 FT
222 squared_circumradiusC2(const FT &px, const FT &py,
223  const FT &qx, const FT &qy,
224  const FT &rx, const FT &ry,
225  FT &x, FT &y )
226 {
227  circumcenter_translateC2(qx-px, qy-py, rx-px, ry-py, x, y);
228  FT r2 = CGAL_NTS square(x) + CGAL_NTS square(y);
229  x += px;
230  y += py;
231  return r2;
232 }
233 
234 template < class FT >
236 FT
237 squared_circumradiusC2(const FT &px, const FT &py,
238  const FT &qx, const FT &qy,
239  const FT &rx, const FT &ry)
240 {
241  FT x, y;
242  circumcenter_translateC2(qx-px, qy-py, rx-px, ry-py, x, y);
243  return CGAL_NTS square(x) + CGAL_NTS square(y);
244 }
245 
246 template < class FT >
248 FT
249 squared_distanceC2( const FT &px, const FT &py,
250  const FT &qx, const FT &qy)
251 {
252  return CGAL_NTS square(px-qx) + CGAL_NTS square(py-qy);
253 }
254 
255 template < class FT >
257 FT
258 scaled_distance_to_lineC2( const FT &la, const FT &lb, const FT &lc,
259  const FT &px, const FT &py)
260 {
261  // for comparisons, use distance_to_directionsC2 instead
262  // since lc is irrelevant
263  return la*px + lb*py + lc;
264 }
265 
266 template < class FT >
268 FT
269 scaled_distance_to_directionC2( const FT &la, const FT &lb,
270  const FT &px, const FT &py)
271 {
272  // scalar product with direction
273  return la*px + lb*py;
274 }
275 
276 template < class FT >
278 FT
279 scaled_distance_to_lineC2( const FT &px, const FT &py,
280  const FT &qx, const FT &qy,
281  const FT &rx, const FT &ry)
282 {
283  return det2x2_by_formula(px-rx,py-ry,qx-rx,qy-ry);
284 }
285 
287 
288 #endif // CGAL_CONSTRUCTIONS_KERNEL_FTC2_H
FT line_y_at_xC2(const FT &a, const FT &b, const FT &c, const FT &x)
CGAL_KERNEL_MEDIUM_INLINE void circumcenterC2(const FT &px, const FT &py, const FT &qx, const FT &qy, const FT &rx, const FT &ry, FT &x, FT &y)
double square(double x)
CGAL_BEGIN_NAMESPACE FT det2x2_by_formula(const FT &a00, const FT &a01, const FT &a10, const FT &a11)
Definition: determinant.h:59
void line_get_pointC2(const FT &a, const FT &b, const FT &c, int i, FT &x, FT &y)
const NT & d
void int int REAL REAL * y
Definition: read.cpp:74
NT dx
#define CGAL_KERNEL_INLINE
Definition: kernel_basic.h:54
CGAL_KERNEL_INLINE FT squared_distanceC2(const FT &px, const FT &py, const FT &qx, const FT &qy)
void perpendicular_through_pointC2(const FT &la, const FT &lb, const FT &px, const FT &py, FT &a, FT &b, FT &c)
CGAL_BEGIN_NAMESPACE CGAL_KERNEL_INLINE void midpointC2(const FT &px, const FT &py, const FT &qx, const FT &qy, FT &x, FT &y)
void line_from_point_directionC2(const FT &px, const FT &py, const FT &dx, const FT &dy, FT &a, FT &b, FT &c)
NT & den
CGAL_KERNEL_INLINE void bisector_of_pointsC2(const FT &px, const FT &py, const FT &qx, const FT &qy, FT &a, FT &b, FT &c)
CGAL_KERNEL_LARGE_INLINE void circumcenter_translateC2(const FT &dqx, const FT &dqy, const FT &drx, const FT &dry, FT &dcx, FT &dcy)
#define CGAL_KERNEL_MEDIUM_INLINE
Definition: kernel_basic.h:55
CGAL_KERNEL_MEDIUM_INLINE FT squared_circumradiusC2(const FT &px, const FT &py, const FT &qx, const FT &qy, const FT &rx, const FT &ry, FT &x, FT &y)
#define CGAL_KERNEL_LARGE_INLINE
Definition: kernel_basic.h:56
CGAL_KERNEL_MEDIUM_INLINE void line_project_pointC2(const FT &la, const FT &lb, const FT &lc, const FT &px, const FT &py, FT &x, FT &y)
blockLoc i
Definition: read.cpp:79
void int int REAL * x
Definition: read.cpp:74
CGAL_KERNEL_INLINE FT scaled_distance_to_directionC2(const FT &la, const FT &lb, const FT &px, const FT &py)
NT dy
void line_from_pointsC2(const FT &px, const FT &py, const FT &qx, const FT &qy, FT &a, FT &b, FT &c)
#define CGAL_BEGIN_NAMESPACE
Definition: kdtree_d.h:86
#define CGAL_NTS
#define CGAL_kernel_assertion(EX)
#define CGAL_END_NAMESPACE
Definition: kdtree_d.h:87
CGAL_KERNEL_INLINE FT scaled_distance_to_lineC2(const FT &la, const FT &lb, const FT &lc, const FT &px, const FT &py)