BWAPI
|
00001 // Copyright (c) 2000 Utrecht University (The Netherlands), 00002 // ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany), 00003 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg 00004 // (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria), 00005 // and Tel-Aviv University (Israel). All rights reserved. 00006 // 00007 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or 00008 // modify it under the terms of the GNU Lesser General Public License as 00009 // published by the Free Software Foundation; version 2.1 of the License. 00010 // See the file LICENSE.LGPL distributed with CGAL. 00011 // 00012 // Licensees holding a valid commercial license may use this file in 00013 // accordance with the commercial license agreement provided with the software. 00014 // 00015 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 // 00018 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Cartesian_kernel/include/CGAL/Cartesian/Plane_3.h $ 00019 // $Id: Plane_3.h 49509 2009-05-20 10:43:29Z spion $ 00020 // 00021 // 00022 // Author(s) : Andreas Fabri 00023 00024 #ifndef CGAL_CARTESIAN_PLANE_3_H 00025 #define CGAL_CARTESIAN_PLANE_3_H 00026 00027 #include <CGAL/array.h> 00028 #include <CGAL/Handle_for.h> 00029 #include <CGAL/Cartesian/solve_3.h> 00030 00031 CGAL_BEGIN_NAMESPACE 00032 00033 template <class R_> 00034 class PlaneC3 00035 { 00036 typedef typename R_::FT FT; 00037 typedef typename R_::Point_2 Point_2; 00038 typedef typename R_::Point_3 Point_3; 00039 typedef typename R_::Vector_3 Vector_3; 00040 typedef typename R_::Direction_3 Direction_3; 00041 typedef typename R_::Line_3 Line_3; 00042 typedef typename R_::Ray_3 Ray_3; 00043 typedef typename R_::Segment_3 Segment_3; 00044 typedef typename R_::Plane_3 Plane_3; 00045 typedef typename R_::Circle_3 Circle_3; 00046 typedef typename R_::Construct_point_3 Construct_point_3; 00047 typedef typename R_::Construct_point_2 Construct_point_2; 00048 00049 typedef cpp0x::array<FT, 4> Rep; 00050 typedef typename R_::template Handle<Rep>::type Base; 00051 00052 Base base; 00053 00054 public: 00055 00056 typedef R_ R; 00057 00058 PlaneC3() {} 00059 00060 PlaneC3(const Point_3 &p, const Point_3 &q, const Point_3 &r) 00061 { *this = plane_from_points(p, q, r); } 00062 00063 PlaneC3(const Point_3 &p, const Direction_3 &d) 00064 { *this = plane_from_point_direction(p, d); } 00065 00066 PlaneC3(const Point_3 &p, const Vector_3 &v) 00067 { *this = plane_from_point_direction(p, v.direction()); } 00068 00069 PlaneC3(const FT &a, const FT &b, const FT &c, const FT &d) 00070 : base(CGAL::make_array(a, b, c, d)) {} 00071 00072 PlaneC3(const Line_3 &l, const Point_3 &p) 00073 { *this = plane_from_points(l.point(), 00074 l.point()+l.direction().to_vector(), 00075 p); } 00076 00077 PlaneC3(const Segment_3 &s, const Point_3 &p) 00078 { *this = plane_from_points(s.start(), s.end(), p); } 00079 00080 PlaneC3(const Ray_3 &r, const Point_3 &p) 00081 { *this = plane_from_points(r.start(), r.second_point(), p); } 00082 00083 typename R::Boolean operator==(const PlaneC3 &p) const; 00084 typename R::Boolean operator!=(const PlaneC3 &p) const; 00085 00086 const FT & a() const 00087 { 00088 return get(base)[0]; 00089 } 00090 const FT & b() const 00091 { 00092 return get(base)[1]; 00093 } 00094 const FT & c() const 00095 { 00096 return get(base)[2]; 00097 } 00098 const FT & d() const 00099 { 00100 return get(base)[3]; 00101 } 00102 00103 Line_3 perpendicular_line(const Point_3 &p) const; 00104 Plane_3 opposite() const; 00105 00106 Point_3 point() const; 00107 Point_3 projection(const Point_3 &p) const; 00108 Vector_3 orthogonal_vector() const; 00109 Direction_3 orthogonal_direction() const; 00110 Vector_3 base1() const; 00111 Vector_3 base2() const; 00112 00113 Point_3 to_plane_basis(const Point_3 &p) const; 00114 00115 Point_2 to_2d(const Point_3 &p) const; 00116 Point_3 to_3d(const Point_2 &p) const; 00117 00118 typename R::Oriented_side oriented_side(const Point_3 &p) const; 00119 typename R::Boolean has_on_positive_side(const Point_3 &l) const; 00120 typename R::Boolean has_on_negative_side(const Point_3 &l) const; 00121 typename R::Boolean has_on(const Point_3 &p) const 00122 { 00123 return oriented_side(p) == ON_ORIENTED_BOUNDARY; 00124 } 00125 typename R::Boolean has_on(const Line_3 &l) const 00126 { 00127 return has_on(l.point()) 00128 && has_on(l.point() + l.direction().to_vector()); 00129 } 00130 typename R::Boolean has_on(const Circle_3 &circle) const 00131 { 00132 if(circle.squared_radius() != FT(0)) { 00133 const Plane_3& p = circle.supporting_plane(); 00134 if(is_zero(a())) { 00135 if(!is_zero(p.a())) return false; 00136 if(is_zero(b())) { 00137 if(!is_zero(p.b())) return false; 00138 return c() * p.d() == d() * p.c(); 00139 } 00140 return (p.c() * b() == c() * p.b()) && 00141 (p.d() * b() == d() * p.b()); 00142 } 00143 return (p.b() * a() == b() * p.a()) && 00144 (p.c() * a() == c() * p.a()) && 00145 (p.d() * a() == d() * p.a()); 00146 } else return has_on(circle.center()); 00147 } 00148 00149 typename R::Boolean is_degenerate() const; 00150 }; 00151 00152 template < class R > 00153 CGAL_KERNEL_INLINE 00154 typename R::Boolean 00155 PlaneC3<R>::operator==(const PlaneC3<R> &p) const 00156 { 00157 if (CGAL::identical(base, p.base)) 00158 return true; 00159 return equal_plane(*this, p); 00160 } 00161 00162 template < class R > 00163 inline 00164 typename R::Boolean 00165 PlaneC3<R>::operator!=(const PlaneC3<R> &p) const 00166 { 00167 return !(*this == p); 00168 } 00169 00170 template < class R > 00171 inline 00172 typename PlaneC3<R>::Point_3 00173 PlaneC3<R>::point() const 00174 { 00175 return point_on_plane(*this); 00176 } 00177 00178 template < class R > 00179 inline 00180 typename PlaneC3<R>::Point_3 00181 PlaneC3<R>:: 00182 projection(const typename PlaneC3<R>::Point_3 &p) const 00183 { 00184 return projection_plane(p, *this); 00185 } 00186 00187 template < class R > 00188 inline 00189 typename PlaneC3<R>::Vector_3 00190 PlaneC3<R>::orthogonal_vector() const 00191 { 00192 return R().construct_orthogonal_vector_3_object()(*this); 00193 } 00194 00195 template < class R > 00196 inline 00197 typename PlaneC3<R>::Direction_3 00198 PlaneC3<R>::orthogonal_direction() const 00199 { 00200 return Direction_3(a(), b(), c()); 00201 } 00202 00203 template < class R > 00204 typename PlaneC3<R>::Vector_3 00205 PlaneC3<R>::base1() const 00206 { 00207 return R().construct_base_vector_3_object()(*this, 1); 00208 } 00209 00210 template < class R > 00211 typename PlaneC3<R>::Vector_3 00212 PlaneC3<R>::base2() const 00213 { 00214 return R().construct_base_vector_3_object()(*this, 2); 00215 } 00216 00217 template < class R > 00218 typename PlaneC3<R>::Point_3 00219 PlaneC3<R>:: 00220 to_plane_basis(const typename PlaneC3<R>::Point_3 &p) const 00221 { 00222 FT alpha, beta, gamma; 00223 Construct_point_3 construct_point_3; 00224 Cartesian_internal::solve(base1(), base2(), orthogonal_vector(), p - point(), 00225 alpha, beta, gamma); 00226 00227 return construct_point_3(alpha, beta, gamma); 00228 } 00229 00230 template < class R > 00231 typename PlaneC3<R>::Point_2 00232 PlaneC3<R>:: 00233 to_2d(const typename PlaneC3<R>::Point_3 &p) const 00234 { 00235 FT alpha, beta, gamma; 00236 Construct_point_2 construct_point_2; 00237 00238 Cartesian_internal::solve(base1(), base2(), orthogonal_vector(), p - point(), 00239 alpha, beta, gamma); 00240 00241 return construct_point_2(alpha, beta); 00242 } 00243 00244 template < class R > 00245 inline 00246 typename PlaneC3<R>::Point_3 00247 PlaneC3<R>:: 00248 to_3d(const typename PlaneC3<R>::Point_2 &p) const 00249 { 00250 return R().construct_lifted_point_3_object()(*this, p); 00251 } 00252 00253 template < class R > 00254 inline 00255 typename PlaneC3<R>::Line_3 00256 PlaneC3<R>:: 00257 perpendicular_line(const typename PlaneC3<R>::Point_3 &p) const 00258 { 00259 return Line_3(p, orthogonal_direction()); 00260 } 00261 00262 template < class R > 00263 inline 00264 typename PlaneC3<R>::Plane_3 00265 PlaneC3<R>::opposite() const 00266 { 00267 return PlaneC3<R>(-a(), -b(), -c(), -d()); 00268 } 00269 00270 template < class R > 00271 inline 00272 typename R::Oriented_side 00273 PlaneC3<R>:: 00274 oriented_side(const typename PlaneC3<R>::Point_3 &p) const 00275 { 00276 return side_of_oriented_plane(*this, p); 00277 } 00278 00279 template < class R > 00280 inline 00281 typename R::Boolean 00282 PlaneC3<R>:: 00283 has_on_positive_side(const typename PlaneC3<R>::Point_3 &p) const 00284 { 00285 return oriented_side(p) == ON_POSITIVE_SIDE; 00286 } 00287 00288 template < class R > 00289 inline 00290 typename R::Boolean 00291 PlaneC3<R>:: 00292 has_on_negative_side(const typename PlaneC3<R>::Point_3 &p) const 00293 { 00294 return oriented_side(p) == ON_NEGATIVE_SIDE; 00295 } 00296 00297 template < class R > 00298 inline 00299 typename R::Boolean 00300 PlaneC3<R>:: 00301 is_degenerate() const 00302 { // FIXME : predicate 00303 return CGAL_NTS is_zero(a()) && CGAL_NTS is_zero(b()) && 00304 CGAL_NTS is_zero(c()); 00305 } 00306 00307 CGAL_END_NAMESPACE 00308 00309 #endif // CGAL_CARTESIAN_PLANE_3_H