Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
constructions/kernel_ftC3.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_ftC3.h
37 // package : C3 (5.2)
38 // revision : $Revision: 1.1.1.1 $
39 // revision_date : $Date: 2001/07/05 22:17:49 $
40 // author(s) : Herve Bronnimann
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_FTC3_H
49 #define CGAL_CONSTRUCTIONS_KERNEL_FTC3_H
50 
51 #include <CGAL/determinant.h>
52 
54 
55 template < class FT >
57 void
58 midpointC3( const FT &px, const FT &py, const FT &pz,
59  const FT &qx, const FT &qy, const FT &qz,
60  FT &x, FT &y, FT &z)
61 {
62  FT half = FT(1) / FT(2);
63  x = (px+qx) * half;
64  y = (py+qy) * half;
65  z = (pz+qz) * half;
66 }
67 
68 template < class FT >
69 void
70 circumcenterC3( const FT &px, const FT &py, const FT &pz,
71  const FT &qx, const FT &qy, const FT &qz,
72  const FT &rx, const FT &ry, const FT &rz,
73  const FT &sx, const FT &sy, const FT &sz,
74  FT &x, FT &y, FT &z)
75 {
76  // Translate s to origin to simplify the expression.
77  FT psx = px-sx;
78  FT psy = py-sy;
79  FT psz = pz-sz;
80  FT ps2 = CGAL_NTS square(psx) + CGAL_NTS square(psy) + CGAL_NTS square(psz);
81  FT qsx = qx-sx;
82  FT qsy = qy-sy;
83  FT qsz = qz-sz;
84  FT qs2 = CGAL_NTS square(qsx) + CGAL_NTS square(qsy) + CGAL_NTS square(qsz);
85  FT rsx = rx-sx;
86  FT rsy = ry-sy;
87  FT rsz = rz-sz;
88  FT rs2 = CGAL_NTS square(rsx) + CGAL_NTS square(rsy) + CGAL_NTS square(rsz);
89 
90  FT num_x = det3x3_by_formula(psy,psz,ps2,
91  qsy,qsz,qs2,
92  rsy,rsz,rs2);
93  FT num_y = det3x3_by_formula(psx,psz,ps2,
94  qsx,qsz,qs2,
95  rsx,rsz,rs2);
96  FT num_z = det3x3_by_formula(psx,psy,ps2,
97  qsx,qsy,qs2,
98  rsx,rsy,rs2);
99  FT den = det3x3_by_formula(psx,psy,psz,
100  qsx,qsy,qsz,
101  rsx,rsy,rsz);
102  CGAL_kernel_assertion( den != FT(0) );
103  FT inv = FT(1)/(FT(2) * den);
104 
105  x = sx + num_x*inv;
106  y = sy - num_y*inv;
107  z = sz + num_z*inv;
108 }
109 
110 template < class FT >
111 void
112 circumcenterC3( const FT &px, const FT &py, const FT &pz,
113  const FT &qx, const FT &qy, const FT &qz,
114  const FT &sx, const FT &sy, const FT &sz,
115  FT &x, FT &y, FT &z)
116 {
117  // Translate s to origin to simplify the expression.
118  FT psx = px-sx;
119  FT psy = py-sy;
120  FT psz = pz-sz;
121  FT ps2 = CGAL_NTS square(psx) + CGAL_NTS square(psy) + CGAL_NTS square(psz);
122  FT qsx = qx-sx;
123  FT qsy = qy-sy;
124  FT qsz = qz-sz;
125  FT qs2 = CGAL_NTS square(qsx) + CGAL_NTS square(qsy) + CGAL_NTS square(qsz);
126  FT rsx = psy*qsz-psz*qsy;
127  FT rsy = psz*qsx-psx*qsz;
128  FT rsz = psx*qsy-psy*qsx;
129 
130  FT num_x = det3x3_by_formula(psy,psz,ps2,
131  qsy,qsz,qs2,
132  rsy,rsz,FT(0));
133  FT num_y = det3x3_by_formula(psx,psz,ps2,
134  qsx,qsz,qs2,
135  rsx,rsz,FT(0));
136  FT num_z = det3x3_by_formula(psx,psy,ps2,
137  qsx,qsy,qs2,
138  rsx,rsy,FT(0));
139  FT den = det3x3_by_formula(psx,psy,psz,
140  qsx,qsy,qsz,
141  rsx,rsy,rsz);
142  CGAL_kernel_assertion( den != FT(0) );
143  FT inv = FT(1)/(FT(2) * den);
144 
145  x = sx + num_x*inv;
146  y = sy - num_y*inv;
147  z = sz + num_z*inv;
148 }
149 
150 template <class FT>
152 void
153 point_on_lineC3(const FT &lpx, const FT &lpy, const FT &lpz,
154  const FT &ldx, const FT &ldy, const FT &ldz,
155  int i,
156  FT &x, FT &y, FT &z)
157 {
158  x = lpx + ldx*FT(i);
159  y = lpy + ldy*FT(i);
160  z = lpz + ldz*FT(i);
161 }
162 
163 template <class FT>
165 void
166 projection_lineC3(const FT &px, const FT &py, const FT &pz,
167  const FT &lpx, const FT &lpy, const FT &lpz,
168  const FT &ldx, const FT &ldy, const FT &ldz,
169  FT &x, FT &y, FT &z)
170 {
171  // projects p on the line l
172  FT dpx = px-lpx;
173  FT dpy = py-lpy;
174  FT dpz = pz-lpz;
175  FT lambda = (ldx*dpx+ldy*dpy+ldz*dpz) / (ldx*ldx+ldy*ldy+ldz*ldz);
176  x = lpx + lambda * ldx;
177  y = lpy + lambda * ldy;
178  z = lpz + lambda * ldz;
179 }
180 
181 template <class FT>
183 void
184 plane_from_pointsC3(const FT &px, const FT &py, const FT &pz,
185  const FT &qx, const FT &qy, const FT &qz,
186  const FT &rx, const FT &ry, const FT &rz,
187  FT &pa, FT &pb, FT &pc, FT &pd)
188 {
189  FT rpx = px-rx;
190  FT rpy = py-ry;
191  FT rpz = pz-rz;
192  FT rqx = qx-rx;
193  FT rqy = qy-ry;
194  FT rqz = qz-rz;
195  // Cross product rp * rq
196  pa = rpy*rqz - rqy*rpz;
197  pb = rpz*rqx - rqz*rpx;
198  pc = rpx*rqy - rqx*rpy;
199  pd = - pa*rx - pb*ry - pc*rz;
200 }
201 
202 template <class FT>
204 void
205 plane_from_point_directionC3(const FT &px, const FT &py, const FT &pz,
206  const FT &dx, const FT &dy, const FT &dz,
207  FT &pa, FT &pb, FT &pc, FT &pd)
208 {
209  // d is the normal direction
210  pa = dx; pb = dy; pc = dz; pd = -dx*px - dy*py - dz*pz;
211 }
212 
213 template <class FT>
215 void
216 point_on_planeC3(const FT &pa, const FT &pb, const FT &pc, const FT &pd,
217  FT &x, FT &y, FT &z)
218 {
219  x = y = z = FT(0);
220  if (pa != FT(0)) x = -pd/pa;
221  else if (pb != FT(0)) y = -pd/pb;
222  else z = -pd/pc;
223 }
224 
225 template <class FT>
227 void
228 projection_planeC3(const FT &pa, const FT &pb, const FT &pc, const FT &pd,
229  const FT &px, const FT &py, const FT &pz,
230  FT &x, FT &y, FT &z)
231 {
232  // the equation of the plane is Ax+By+Cz+D=0
233  // the normal direction is (A,B,C)
234  // the projected point is p-lambda(A,B,C) where
235  // A(x-lambda A) + B(y-lambda B) + C(z-lambda C) + D = 0
236 
237  FT num = pa*px + pb*py + pc*pz + pd;
238  FT den = pa*pa + pb*pb + pc*pc;
239  FT lambda = num / den;
240 
241  x = px - lambda * pa;
242  y = py - lambda * pb;
243  z = pz - lambda * pc;
244 }
245 
246 template < class FT >
248 FT
249 squared_distanceC3( const FT &px, const FT &py, const FT &pz,
250  const FT &qx, const FT &qy, const FT &qz)
251 {
252  return CGAL_NTS square(px-qx) + CGAL_NTS square(py-qy) +
253  CGAL_NTS square(pz-qz);
254 }
255 
256 template < class FT >
258 FT
259 scaled_distance_to_directionC3(const FT &pa, const FT &pb, const FT &pc,
260  const FT &px, const FT &py, const FT &pz)
261 {
262  return pa*px + pb*py + pc*pz;
263 }
264 
265 template < class FT >
267 FT
269  const FT &pa, const FT &pb, const FT &pc, const FT &pd,
270  const FT &px, const FT &py, const FT &pz)
271 {
272  return pa*px + pb*py + pc*pz + pd;
273 }
274 
275 template < class FT >
277 FT
279  const FT &ppx, const FT &ppy, const FT &ppz,
280  const FT &pqx, const FT &pqy, const FT &pqz,
281  const FT &prx, const FT &pry, const FT &prz,
282  const FT &px, const FT &py, const FT &pz)
283 {
284  return det3x3_by_formula(ppx-px,ppy-py,ppz-pz,
285  pqx-px,pqy-py,pqz-pz,
286  prx-px,pry-py,prz-pz);
287 }
288 
290 
291 #endif // CGAL_CONSTRUCTIONS_KERNEL_FTC3_H
double square(double x)
CGAL_KERNEL_MEDIUM_INLINE void projection_planeC3(const FT &pa, const FT &pb, const FT &pc, const FT &pd, const FT &px, const FT &py, const FT &pz, FT &x, FT &y, FT &z)
void int int REAL REAL * y
Definition: read.cpp:74
NT dx
#define CGAL_KERNEL_INLINE
Definition: kernel_basic.h:54
CGAL_KERNEL_MEDIUM_INLINE FT det3x3_by_formula(const FT &a00, const FT &a01, const FT &a02, const FT &a10, const FT &a11, const FT &a12, const FT &a20, const FT &a21, const FT &a22)
Definition: determinant.h:71
CGAL_KERNEL_INLINE FT scaled_distance_to_planeC3(const FT &pa, const FT &pb, const FT &pc, const FT &pd, const FT &px, const FT &py, const FT &pz)
NT & den
#define CGAL_KERNEL_MEDIUM_INLINE
Definition: kernel_basic.h:55
CGAL_KERNEL_MEDIUM_INLINE void plane_from_pointsC3(const FT &px, const FT &py, const FT &pz, const FT &qx, const FT &qy, const FT &qz, const FT &rx, const FT &ry, const FT &rz, FT &pa, FT &pb, FT &pc, FT &pd)
CGAL_KERNEL_MEDIUM_INLINE void plane_from_point_directionC3(const FT &px, const FT &py, const FT &pz, const FT &dx, const FT &dy, const FT &dz, FT &pa, FT &pb, FT &pc, FT &pd)
void int int int REAL REAL REAL * z
Definition: write.cpp:76
CGAL_KERNEL_INLINE FT squared_distanceC3(const FT &px, const FT &py, const FT &pz, const FT &qx, const FT &qy, const FT &qz)
CGAL_BEGIN_NAMESPACE CGAL_KERNEL_INLINE void midpointC3(const FT &px, const FT &py, const FT &pz, const FT &qx, const FT &qy, const FT &qz, FT &x, FT &y, FT &z)
blockLoc i
Definition: read.cpp:79
void int int REAL * x
Definition: read.cpp:74
CGAL_KERNEL_MEDIUM_INLINE void point_on_planeC3(const FT &pa, const FT &pb, const FT &pc, const FT &pd, FT &x, FT &y, FT &z)
NT dy
void inv(Matrix3D &Ainv, const Matrix3D &A)
void circumcenterC3(const FT &px, const FT &py, const FT &pz, const FT &qx, const FT &qy, const FT &qz, const FT &rx, const FT &ry, const FT &rz, const FT &sx, const FT &sy, const FT &sz, FT &x, FT &y, FT &z)
#define CGAL_BEGIN_NAMESPACE
Definition: kdtree_d.h:86
#define CGAL_NTS
CGAL_KERNEL_MEDIUM_INLINE void point_on_lineC3(const FT &lpx, const FT &lpy, const FT &lpz, const FT &ldx, const FT &ldy, const FT &ldz, int i, FT &x, FT &y, FT &z)
CGAL_KERNEL_INLINE FT scaled_distance_to_directionC3(const FT &pa, const FT &pb, const FT &pc, const FT &px, const FT &py, const FT &pz)
#define CGAL_kernel_assertion(EX)
#define CGAL_END_NAMESPACE
Definition: kdtree_d.h:87
CGAL_KERNEL_MEDIUM_INLINE void projection_lineC3(const FT &px, const FT &py, const FT &pz, const FT &lpx, const FT &lpy, const FT &lpz, const FT &ldx, const FT &ldy, const FT &ldz, FT &x, FT &y, FT &z)