Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PlaneS3.h
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // Copyright (c) 1999 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 // release : CGAL-2.2
33 // release_date : 2000, September 30
34 //
35 // source : webS3/S3.lw
36 // file : include/CGAL/SimpleCartesian/PlaneS3.h
37 // package : S3 (1.6)
38 // revision : 1.6
39 // revision_date : 28 Jun 2000
40 // author(s) : Stefan Schirra
41 // based on code by
42 // Andreas Fabri and
43 // Herve Brönnimann
44 //
45 // coordinator : MPI, Saarbrücken
46 // email : contact@cgal.org
47 // www : http://www.cgal.org
48 //
49 // ======================================================================
50 
51 #ifndef CGAL_PLANES3_H
52 #define CGAL_PLANES3_H
53 
54 #include <CGAL/SimpleCartesian/PointS2.h>
55 #include <CGAL/solve.h>
57 
59 
60 template < class FT >
61 class PlaneS3
62 {
63 public:
64  PlaneS3() {}
65  PlaneS3(const PointS3<FT>& p,
66  const PointS3<FT>& q,
67  const PointS3<FT>& r);
68  PlaneS3(const PointS3<FT>& p,
69  const DirectionS3<FT>& d);
70  PlaneS3(const PointS3<FT>& p,
71  const VectorS3<FT>& v);
72  PlaneS3(const FT& a, const FT& b,
73  const FT& c, const FT& d);
74  PlaneS3(const LineS3<FT>& l,
75  const PointS3<FT>& p);
76  PlaneS3(const SegmentS3<FT>& s,
77  const PointS3<FT>& p);
78  PlaneS3(RayS3<FT>& r,
79  const PointS3<FT>& p);
80 
81  bool operator==(const PlaneS3<FT>& p) const;
82  bool operator!=(const PlaneS3<FT>& p) const;
83 
84  const FT& a() const;
85  const FT& b() const;
86  const FT& c() const;
87  const FT& d() const;
88 
90  PlaneS3 opposite() const;
91 
92  PointS3<FT> point() const;
93  PointS3<FT> projection(const PointS3<FT>& p) const;
96  VectorS3<FT> base1() const;
97  VectorS3<FT> base2() const;
98 
99  PointS3<FT> to_plane_basis(const PointS3<FT>& p) const;
100 
101  PointS2<FT> to_2d(const PointS3<FT>& p) const;
102  PointS3<FT> to_3d(const PointS2<FT>& p) const;
103 
105 
106 
107  Oriented_side oriented_side(const PointS3<FT>& p) const;
108  bool has_on_boundary(const PointS3<FT>& p) const;
109  bool has_on_boundary(const LineS3<FT>& p) const;
110  bool has_on_positive_side(const PointS3<FT>& l) const;
111  bool has_on_negative_side(const PointS3<FT>& l) const;
112 
113  bool is_degenerate() const;
114 
115 // private:
116  void new_rep(const PointS3<FT>& p,
117  const PointS3<FT>& q,
118  const PointS3<FT>& r);
119  void new_rep(const FT& a, const FT& b,
120  const FT& c, const FT& d);
121 
122  FT e0;
123  FT e1;
124  FT e2;
125  FT e3;
126 };
127 
128 
129 template < class FT >
130 inline
131 void
132 PlaneS3<FT>::new_rep(const FT& a, const FT& b, const FT& c, const FT& d)
133 {
134  e0 = a;
135  e1 = b;
136  e2 = c;
137  e3 = d;
138 }
139 
140 template < class FT >
141 inline
142 void
144  const PointS3<FT>& q,
145  const PointS3<FT>& r)
146 {
147  FT rpx = p.x()-r.x();
148  FT rpy = p.y()-r.y();
149  FT rpz = p.z()-r.z();
150  FT rqx = q.x()-r.x();
151  FT rqy = q.y()-r.y();
152  FT rqz = q.z()-r.z();
153  // Cross product rp * rq.
154  e0 = rpy*rqz - rqy*rpz;
155  e1 = rpz*rqx - rqz*rpx;
156  e2 = rpx*rqy - rqx*rpy;
157  e3 = - e0*r.x() - e1*r.y() - e2*r.z();
158 }
159 
160 
162 
164 
166 
167 
168 template < class FT >
170  const PointS3<FT>& q,
171  const PointS3<FT>& r)
172 { new_rep(p, q, r); }
173 
174 template < class FT >
176 {
177  new_rep(d.dx(), d.dy(),
178  d.dz(),
179  -d.dx() * p.x() - d.dy() * p.y() - d.dz() * p.z());
180 }
181 
182 template < class FT >
184 { new_rep(v.x(), v.y(), v.z(), -v.x() * p.x() - v.y() * p.y() - v.z() * p.z()); }
185 
186 template < class FT >
187 PlaneS3<FT>::PlaneS3(const FT& a, const FT& b, const FT& c, const FT& d)
188 { new_rep(a, b, c, d); }
189 
190 template < class FT >
192 { new_rep(l.point(), l.point()+l.direction().vector(), p); }
193 
194 template < class FT >
196 { new_rep(s.start(), s.end(), p); }
197 
198 template < class FT >
200 { new_rep(r.start(), r.second_point(), p); }
201 
202 
203 template < class FT >
205 {
206  return has_on_boundary(p.point()) &&
207  (orthogonal_direction() == p.orthogonal_direction());
208 
209 }
210 
211 template < class FT >
213 {
214  return !(*this == p);
215 }
216 
217 template < class FT >
218 const FT&
220 { return e0; }
221 
222 template < class FT >
223 const FT&
225 { return e1; }
226 
227 template < class FT >
228 const FT&
230 { return e2; }
231 
232 template < class FT >
233 const FT&
235 { return e3; }
236 
237 template < class FT >
239 {
240  if (a() != FT(0)) // not parallel to x-axis
241  return PointS3<FT>(-d()/a(), FT(0), FT(0));
242  if (b() != FT(0)) // not parallel to y-axis
243  return PointS3<FT>(FT(0), -d()/b(), FT(0));
244  // parallel to xy-plane => intersects z-axis
245  return PointS3<FT>(FT(0), FT(0), -d()/c());
246 }
247 
248 template < class FT >
251 {
252  return CGAL::projection(p, *this);
253 }
254 
255 template < class FT >
257 {
258  return VectorS3<FT>(a(), b(), c());
259 }
260 
261 
262 template < class FT >
264 {
265  return DirectionS3<FT>(a(), b(), c());
266 }
267 
268 template < class FT >
270 {
271  if( a() == FT(0) ) // parallel to x-axis
272  return VectorS3<FT>(FT(1), FT(0), FT(0));
273 
274  if( b() == FT(0) ) // parallel to y-axis
275  return VectorS3<FT>(FT(0), FT(1), FT(0));
276 
277  if (c() == FT(0) ) // parallel to z-axis
278  return VectorS3<FT>(FT(0), FT(0), FT(1));
279 
280  return VectorS3<FT>(-b(), a(), FT(0));
281 }
282 
283 
284 template < class FT >
286 {
287  if ( a() == FT(0) ) // parallel to x-axis x-axis already returned in base1
288  {
289  if (b() == FT(0) ) // parallel to y-axis
290  return VectorS3<FT>(FT(0), FT(1), FT(0));
291 
292  if (c() == FT(0) ) // parallel to z-axis
293  return VectorS3<FT>(FT(0), FT(0), FT(1));
294 
295  return VectorS3<FT>(FT(0), -b(), c());
296  }
297  if (b() == FT(0) )
298  return VectorS3<FT>(c(), FT(0), -a());
299 
300  if (c() == FT(0) )
301  return VectorS3<FT>(-b(), a(), FT(0));
302 
303  return VectorS3<FT>(FT(0), -c(), b());
304 }
305 template < class FT >
307 {
308  const VectorS3<FT>& v0 = base1();
309  const VectorS3<FT>& v1 = base2();
310  VectorS3<FT> v2 = orthogonal_vector();
311  VectorS3<FT> v3 = p - point();
312  FT alpha, beta, gamma;
313 
314  solve(v0.x(), v0.y(), v0.z(),
315  v1.x(), v1.y(), v1.z(),
316  v2.x(), v2.y(), v2.z(),
317  v3.x(), v3.y(), v3.z(),
318  alpha, beta, gamma);
319 
320  return PointS3<FT>(alpha, beta, gamma);
321 }
322 
323 template < class FT >
325 {
326  const VectorS3<FT>& v0 = base1();
327  const VectorS3<FT>& v1 = base2();
328  VectorS3<FT> v2 = orthogonal_vector();
329  VectorS3<FT> v3 = p - point();
330  FT alpha, beta, gamma;
331 
332  solve(v0.x(), v0.y(), v0.z(),
333  v1.x(), v1.y(), v1.z(),
334  v2.x(), v2.y(), v2.z(),
335  v3.x(), v3.y(), v3.z(),
336  alpha, beta, gamma);
337 
338  return PointS2<FT>(alpha, beta);
339 }
340 
341 
342 template < class FT >
344 {
345  VectorS3<FT> e1 = base1(),
346  e2 = base2();
347  return point() + p.x() * e1 + p.y() * e2;
348 }
349 
350 template < class FT >
352 { return LineS3<FT>(p, orthogonal_direction()); }
353 
354 
355 template < class FT >
357 { return PlaneS3<FT>(-a(),-b(),-c(),-d()); }
358 
359 
360 template < class FT >
362 {
363  DirectionS3<FT> dir = t.transpose().inverse().transform(orthogonal_direction());
364  if (!t.is_even()) dir = -dir;
365  return PlaneS3<FT>( t.transform(point()), dir);
366 
367 /*
368  return PlaneS3<FT>( t.transform(point()), (t.is_even())
369  ? t.transpose().inverse().transform(orthogonal_direction())
370  : - t.transpose().inverse().transform(orthogonal_direction()) );
371 */
372 }
373 
374 
375 template < class FT >
377 { return Oriented_side(CGAL_NTS sign(a()*p.x() + b()*p.y() + c()*p.z() +d())); }
378 
379 template < class FT >
381 {
382  return (a()*p.x() + b()*p.y() + c()*p.z() +d()) == FT(0);
383 }
384 
385 template < class FT >
387 {
388  return has_on_boundary(l.point())
389  && has_on_boundary(l.point() + l.direction().vector());
390 }
391 
392 template < class FT >
394 {
395  return (a()*p.x() + b()*p.y() + c()*p.z() +d()) > FT(0);
396 }
397 
398 template < class FT >
400 {
401  return (a()*p.x() + b()*p.y() + c()*p.z() +d()) < FT(0);
402 }
403 
404 
405 template < class FT >
407 {
408  return (a() == FT(0)) && (b() == FT(0)) && (c() == FT(0));
409 }
410 
411 
412 #ifndef CGAL_NO_OSTREAM_INSERT_PLANES3
413 template < class FT >
414 std::ostream& operator<<(std::ostream& os, const PlaneS3<FT>& p)
415 {
416  switch(os.iword(IO::mode)) {
417  case IO::ASCII :
418  return os << p.a() << ' ' << p.b() << ' ' << p.c() << ' ' << p.d();
419  case IO::BINARY :
420  write(os, p.a());
421  write(os, p.b());
422  write(os, p.c());
423  write(os, p.d());
424  return os;
425  default:
426  os << "PlaneS3(" << p.a() << ", " << p.b() << ", ";
427  os << p.c() << ", " << p.d() <<")";
428  return os;
429  }
430 }
431 #endif // CGAL_NO_OSTREAM_INSERT_PLANES3
432 
433 #ifndef CGAL_NO_ISTREAM_EXTRACT_PLANES3
434 template < class FT >
435 std::istream& operator>>(std::istream& is, PlaneS3<FT>& p)
436 {
437  FT a, b, c, d;
438  switch(is.iword(IO::mode)) {
439  case IO::ASCII :
440  is >> a >> b >> c >> d;
441  break;
442  case IO::BINARY :
443  read(is, a);
444  read(is, b);
445  read(is, c);
446  read(is, d);
447  break;
448  default:
449  cerr << "" << endl;
450  cerr << "Stream must be in ascii or binary mode" << endl;
451  break;
452  }
453  p = PlaneS3<FT>(a, b, c, d);
454  return is;
455 }
456 #endif // CGAL_NO_ISTREAM_EXTRACT_PLANES3
457 
458 
460 
461 #endif // CGAL_PLANES3_H
Oriented_side oriented_side(const PointS3< FT > &p) const
Definition: PlaneS3.h:376
const FT & d() const
Definition: PlaneS3.h:234
PlaneS3 transform(const Aff_transformationS3< FT > &t) const
Definition: PlaneS3.h:361
PlaneS3()
Definition: PlaneS3.h:64
const FT & dx() const
Definition: DirectionS3.h:155
Aff_transformationS3< FT > transpose() const
FT e2
Definition: PlaneS3.h:124
static SURF_BEGIN_NAMESPACE double sign(double x)
const NT & d
bool operator==(const PlaneS3< FT > &p) const
Definition: PlaneS3.h:204
double s
Definition: blastest.C:80
const FT & dz() const
Definition: DirectionS3.h:169
bool has_on_negative_side(const PointS3< FT > &l) const
Definition: PlaneS3.h:399
bool has_on_positive_side(const PointS3< FT > &l) const
Definition: PlaneS3.h:393
PointS3< FT > projection(const PointS3< FT > &p) const
Definition: PlaneS3.h:250
PointS3< FT > start() const
Definition: SegmentS3.h:115
PointS3< FT > point() const
Definition: PlaneS3.h:238
bool operator!=(const PlaneS3< FT > &p) const
Definition: PlaneS3.h:212
bool has_on_boundary(const PointS3< FT > &p) const
Definition: PlaneS3.h:380
PointS3< FT > to_3d(const PointS2< FT > &p) const
Definition: PlaneS3.h:343
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
Definition: io.h:64
const FT & c() const
Definition: PlaneS3.h:229
Oriented_side
Definition: enum.h:78
void write(std::ostream &os, const T &t, const io_Read_write &)
Definition: io.h:96
const FT & dy() const
Definition: DirectionS3.h:162
void new_rep(const PointS3< FT > &p, const PointS3< FT > &q, const PointS3< FT > &r)
Definition: PlaneS3.h:143
PointS3< FT > end() const
Definition: SegmentS3.h:120
FT e3
Definition: PlaneS3.h:125
const FT & b() const
Definition: PlaneS3.h:224
PointS3< FT > point() const
Definition: LineS3.h:145
VectorS3< FT > orthogonal_vector() const
Definition: PlaneS3.h:256
PointS3< FT > transform(const PointS3< FT > &p) const
PointS3< FT > second_point() const
Definition: RayS3.h:133
static int mode
Definition: io.h:63
Definition: io.h:64
FT e1
Definition: PlaneS3.h:123
VectorS3< FT > base2() const
Definition: PlaneS3.h:285
PlaneS3 opposite() const
Definition: PlaneS3.h:356
PointS2< FT > to_2d(const PointS3< FT > &p) const
Definition: PlaneS3.h:324
const FT & a() const
Definition: PlaneS3.h:219
NT q
VectorS3< FT > base1() const
Definition: PlaneS3.h:269
void read(std::istream &is, T &t, const io_Read_write &)
Definition: io.h:132
PointS3< FT > to_plane_basis(const PointS3< FT > &p) const
Definition: PlaneS3.h:306
bool is_degenerate() const
Definition: PlaneS3.h:406
DirectionS3< FT > orthogonal_direction() const
Definition: PlaneS3.h:263
CGAL_KERNEL_LARGE_INLINE PointS3< FT > projection(const PointS3< FT > &p, const PlaneS3< FT > &h)
Definition: RayS3.h:59
#define CGAL_BEGIN_NAMESPACE
Definition: kdtree_d.h:86
DirectionS3< FT > direction() const
Definition: LineS3.h:150
FT e0
Definition: PlaneS3.h:122
std::istream & operator>>(std::istream &is, CGAL::Aff_transformation_2< R > &t)
PointS3< FT > start() const
Definition: RayS3.h:122
#define CGAL_NTS
LineS3< FT > perpendicular_line(const PointS3< FT > &p) const
Definition: PlaneS3.h:351
#define CGAL_END_NAMESPACE
Definition: kdtree_d.h:87
Definition: LineS3.h:59
CGAL_BEGIN_NAMESPACE void solve(const FT &a1, const FT &a2, const FT &a3, const FT &b1, const FT &b2, const FT &b3, const FT &c1, const FT &c2, const FT &c3, const FT &d1, const FT &d2, const FT &d3, FT &x, FT &y, FT &z)
Definition: solve.h:57