Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LineS2.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 : webS2/S2.lw
36 // file : include/CGAL/SimpleCartesian/LineS2.h
37 // package : S2 (1.7)
38 // revision : 1.6
39 // revision_date : 27 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 
52 #ifndef CGAL_LINES2_H
53 #define CGAL_LINES2_H
54 
58 
60 
61 template < class FT >
62 class LineS2
63 {
64 public:
65  LineS2();
66  LineS2(const PointS2<FT>& p,
67  const PointS2<FT>& q);
68  LineS2(const FT& a, const FT &b, const FT &c);
69  LineS2(const SegmentS2<FT>& s);
70  LineS2(const RayS2<FT>& r);
71  LineS2(const PointS2<FT>& p,
72  const DirectionS2<FT>& d);
73 
74  bool operator==(const LineS2<FT>& l) const;
75  bool operator!=(const LineS2<FT>& l) const;
76 
77  FT a() const;
78  FT b() const;
79  FT c() const;
80 
81  FT x_at_y(const FT& y) const;
82  FT y_at_x(const FT& x) const;
83 
84  LineS2<FT> perpendicular(const PointS2<FT>& p) const;
85  LineS2<FT> opposite() const;
86  PointS2<FT> point(int i) const;
87 
88  PointS2<FT> point() const;
89  PointS2<FT> projection(const PointS2<FT>& p) const;
90 
91  DirectionS2<FT> direction() const;
92 
93  Oriented_side oriented_side(const PointS2<FT>& p) const;
94  bool has_on_boundary(const PointS2<FT>& p) const;
95  bool has_on_positive_side(const PointS2<FT>& p) const;
96  bool has_on_negative_side(const PointS2<FT>& p) const;
97 
98  bool is_horizontal() const;
99  bool is_vertical() const;
100  bool is_degenerate() const;
101 
103 
104 // private:
105  void new_rep(const PointS2<FT>& p, const PointS2<FT> &q);
106  void new_rep(const FT& a, const FT &b, const FT &c);
107 
108  FT e0;
109  FT e1;
110  FT e2;
111 
112 };
113 
114 
115 template < class FT >
116 inline
118 {}
119 
120 template < class FT >
123 {
124  e0 = p.y() - q.y();
125  e1 = q.x() - p.x();
126  e2 = p.x()*q.y() - p.y()*q.x();
127 }
128 
129 template < class FT >
131 void LineS2<FT>::new_rep(const FT& a, const FT &b, const FT &c)
132 {
133  e0 = a;
134  e1 = b;
135  e2 = c;
136 }
137 
138 template < class FT >
139 inline
141 { new_rep(p,q); }
142 
143 template < class FT >
144 inline
145 LineS2<FT>::LineS2(const FT& a, const FT &b, const FT &c)
146 { new_rep(a,b,c); }
147 
148 template < class FT >
149 inline
151 { new_rep( s.start(), s.end()); }
152 
153 template < class FT >
154 inline
156 { new_rep(r.start(), r.second_point()); }
157 
158 template < class FT >
161 { new_rep(-d.dy(), d.dx(), -d.dx()* p.y() + d.dy() * p.x()); }
162 
163 
164 template < class FT >
166 bool LineS2<FT>::operator==(const LineS2<FT>& l) const
167 {
168  if ( (a() * l.c() != l.a() * c())
169  ||(b() * l.c() != l.b() * c()) )
170  return false;
171  int sc = CGAL_NTS sign(c());
172  int slc = CGAL_NTS sign(l.c());
173  if ( sc == slc )
174  return (sc == 0) ? ( a()*l.b() == b()*l.a() )
175  && (CGAL_NTS sign(a() ) == CGAL_NTS sign( l.a() ))
176  && (CGAL_NTS sign(b() ) == CGAL_NTS sign( l.b() ))
177  : true;
178  return false;
179 }
180 
181 template < class FT >
182 inline
183 bool LineS2<FT>::operator!=(const LineS2<FT>& l) const
184 { return !(*this == l); }
185 
186 template < class FT >
187 inline
188 FT LineS2<FT>::a() const
189 { return e0; }
190 
191 template < class FT >
192 inline
193 FT LineS2<FT>::b() const
194 { return e1; }
195 
196 template < class FT >
197 inline
198 FT LineS2<FT>::c() const
199 { return e2; }
200 
201 template < class FT >
203 FT LineS2<FT>::x_at_y(const FT& y) const
204 {
205  CGAL_kernel_precondition_msg( (a() != FT(0)),
206  "Line::x_at_y(const FT& y) is undefined for horizontal line" );
207  return ( -b()*y - c() ) / a();
208 }
209 
210 template < class FT >
212 FT LineS2<FT>::y_at_x(const FT& x) const
213 {
214  CGAL_kernel_precondition_msg( (b() != FT(0)),
215  "Line::x_at_y(const FT& y) is undefined for vertical line");
216  return ( -a()*x - c() ) / b();
217 }
218 
219 template < class FT >
220 inline
222 { return LineS2<FT>( -b() , a() , b() * p.x() - a() * p.y() ); }
223 
224 template < class FT >
225 inline
227 { return LineS2<FT>( -a(), -b(), -c() ); }
228 
229 template < class FT >
232 {
233  if (i == 0)
234  return is_vertical() ? PointS2<FT>( (-b()-c())/a(), FT(1) )
235  : PointS2<FT>( FT(1), -(a()+c())/b());
236  if (i == 1)
237  return is_vertical() ? PointS2<FT>( (-b()-c())/a() + b(), FT(1) - a() )
238  : PointS2<FT>( FT(1) + b(), -(a()+c())/b() - a() );
239  // we add i times the direction
240  if (is_vertical())
241  return PointS2<FT>( (-b()-c())/a() + FT(i)*b(), FT(1) - FT(i)*a() );
242  return PointS2<FT>( FT(1) + FT(i)*b(), -(a()+c())/b() - FT(i)*a() );
243 }
244 
245 template < class FT >
248 {
249  return is_vertical() ? PointS2<FT>( (-b()-c())/a(), FT(1) )
250  : PointS2<FT>( FT(1), -(a()+c())/b());
251 }
252 
253 template < class FT >
256 {
257  if (is_horizontal())
258  return PointS2<FT>(p.x(), -c()/b());
259 
260  if (is_vertical())
261  return PointS2<FT>( -c()/a(), p.y());
262 
263  FT ab = a()/b(), ba = b()/a(), ca = c()/a();
264  FT y = ( -p.x() + ab*p.y() - ca ) / ( ba + ab );
265  return PointS2<FT>(-ba * y - ca, y);
266 }
267 
268 template < class FT >
269 inline
271 { return DirectionS2<FT>( b(), -a() ); }
272 
273 template < class FT >
276 { return Oriented_side(CGAL_NTS sign(a()*p.x() + b()*p.y() + c())); }
277 
278 template < class FT >
279 inline
281 { return (a()*p.x() + b()*p.y() + c()) == FT(0); }
282 
283 template < class FT >
284 inline
286 { return (a()*p.x() + b()*p.y() + c()) > FT(0); }
287 
288 template < class FT >
291 { return (a()*p.x() + b()*p.y() + c()) < FT(0); }
292 
293 template < class FT >
294 inline
296 { return a() == FT(0) ; }
297 
298 template < class FT >
299 inline
301 { return b() == FT(0) ; }
302 
303 template < class FT >
304 inline
306 { return (a() == FT(0)) && (b() == FT(0)) ; }
307 
308 template < class FT >
309 inline
311 { return LineS2<FT>( t.transform(point(0) ), t.transform(direction() )); }
312 
313 
314 
315 #ifndef CGAL_NO_OSTREAM_INSERT_LINES2
316 template < class FT >
317 std::ostream& operator<<(std::ostream &os, const LineS2<FT> &l)
318 {
319 
320  switch(os.iword(IO::mode)) {
321  case IO::ASCII :
322  return os << l.a() << ' ' << l.b() << ' ' << l.c();
323  case IO::BINARY :
324  write(os, l.a());
325  write(os, l.b());
326  write(os, l.c());
327  return os;
328  default:
329  return os << "LineS2(" << l.a() << ", " << l.b() << ", " << l.c() <<')';
330  }
331 }
332 #endif // CGAL_NO_OSTREAM_INSERT_LINES2
333 
334 #ifndef CGAL_NO_ISTREAM_EXTRACT_LINES2
335 template < class FT >
336 std::istream& operator>>(std::istream &is, LineS2<FT> &p)
337 {
338  FT a, b, c;
339  switch(is.iword(IO::mode)) {
340  case IO::ASCII :
341  is >> a >> b >> c;
342  break;
343  case IO::BINARY :
344  read(is, a);
345  read(is, b);
346  read(is, c);
347  break;
348  default:
349  std::cerr << "" << std::endl;
350  std::cerr << "Stream must be in ascii or binary mode" << std::endl;
351  break;
352  }
353  p = LineS2<FT>(a, b, c);
354  return is;
355 }
356 #endif // CGAL_NO_ISTREAM_EXTRACT_LINES2
357 
358 
359 
361 
362 #endif // CGAL_LINES2_H
#define CGAL_kernel_precondition_msg(EX, MSG)
DirectionS2< FT > direction() const
Definition: LineS2.h:270
FT b() const
Definition: LineS2.h:193
bool is_degenerate() const
Definition: LineS2.h:305
FT x_at_y(const FT &y) const
Definition: LineS2.h:203
static SURF_BEGIN_NAMESPACE double sign(double x)
const NT & d
void int int REAL REAL * y
Definition: read.cpp:74
double s
Definition: blastest.C:80
void new_rep(const PointS2< FT > &p, const PointS2< FT > &q)
Definition: LineS2.h:122
#define CGAL_KERNEL_INLINE
Definition: kernel_basic.h:54
LineS2< FT > transform(const Aff_transformationS2< FT > &t) const
Definition: LineS2.h:310
FT e1
Definition: LineS2.h:109
#define CGAL_KERNEL_MEDIUM_INLINE
Definition: kernel_basic.h:55
const PointS2< FT > & start() const
Definition: SegmentS2.h:128
Definition: io.h:64
FT dx() const
Definition: DirectionS2.h:217
FT e2
Definition: LineS2.h:110
PointS2< FT > second_point() const
Definition: RayS2.h:128
Oriented_side
Definition: enum.h:78
bool is_vertical() const
Definition: LineS2.h:300
const PointS2< FT > & start() const
Definition: RayS2.h:116
Definition: RayS2.h:60
PointS2< FT > point() const
Definition: LineS2.h:247
void write(std::ostream &os, const T &t, const io_Read_write &)
Definition: io.h:96
bool has_on_boundary(const PointS2< FT > &p) const
Definition: LineS2.h:280
blockLoc i
Definition: read.cpp:79
Oriented_side oriented_side(const PointS2< FT > &p) const
Definition: LineS2.h:275
void int int REAL * x
Definition: read.cpp:74
LineS2< FT > perpendicular(const PointS2< FT > &p) const
Definition: LineS2.h:221
FT dy() const
Definition: DirectionS2.h:223
FT y_at_x(const FT &x) const
Definition: LineS2.h:212
static int mode
Definition: io.h:63
bool operator!=(const LineS2< FT > &l) const
Definition: LineS2.h:183
Definition: io.h:64
FT e0
Definition: LineS2.h:108
Definition: LineS2.h:62
bool has_on_positive_side(const PointS2< FT > &p) const
Definition: LineS2.h:285
PointS2< FT > transform(const PointS2< FT > &p) const
bool is_horizontal() const
Definition: LineS2.h:295
const PointS2< FT > & end() const
Definition: SegmentS2.h:134
NT q
PointS2< FT > projection(const PointS2< FT > &p) const
Definition: LineS2.h:255
void read(std::istream &is, T &t, const io_Read_write &)
Definition: io.h:132
FT a() const
Definition: LineS2.h:188
bool operator==(const LineS2< FT > &l) const
Definition: LineS2.h:166
LineS2()
Definition: LineS2.h:117
#define CGAL_BEGIN_NAMESPACE
Definition: kdtree_d.h:86
std::istream & operator>>(std::istream &is, CGAL::Aff_transformation_2< R > &t)
#define CGAL_NTS
LineS2< FT > opposite() const
Definition: LineS2.h:226
#define CGAL_END_NAMESPACE
Definition: kdtree_d.h:87
bool has_on_negative_side(const PointS2< FT > &p) const
Definition: LineS2.h:290
FT c() const
Definition: LineS2.h:198