$extrastylesheet
00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 00020 // C++ includes 00021 00022 // Local includes 00023 #include "libmesh/plane.h" 00024 00025 namespace libMesh 00026 { 00027 00028 00029 00030 // ------------------------------------------------------------ 00031 // Plane class member functions 00032 Plane::Plane () 00033 { 00034 } 00035 00036 00037 00038 Plane::Plane (const Point& p, 00039 const Point& n) 00040 { 00041 this->create_from_point_normal (p, n); 00042 } 00043 00044 00045 00046 Plane::Plane (const Point& p0, 00047 const Point& p1, 00048 const Point& p2) 00049 { 00050 this->create_from_three_points (p0, p1, p2); 00051 } 00052 00053 00054 00055 Plane::Plane (const Plane& other_plane) : 00056 Surface() 00057 { 00058 this->create_from_point_normal(other_plane._point, 00059 other_plane._normal); 00060 } 00061 00062 00063 00064 Plane::~Plane () 00065 { 00066 } 00067 00068 00069 00070 void Plane::create_from_point_normal (const Point& p, const Point& n) 00071 { 00072 _normal = n.unit(); 00073 _point = p; 00074 } 00075 00076 00077 00078 void Plane::create_from_three_points (const Point& p0, 00079 const Point& p1, 00080 const Point& p2) 00081 { 00082 // Just use p0 for the point. 00083 _point = p0; 00084 00085 const Point e0 = p1 - p0; 00086 const Point e1 = p2 - p0; 00087 const Point n = e0.cross(e1); 00088 00089 _normal = n.unit(); 00090 } 00091 00092 00093 00094 void Plane::xy_plane (const Real zpos) 00095 { 00096 const Point p (0., 0., zpos); 00097 const Point n (0., 0., 1.); 00098 00099 _point = p; 00100 _normal = n; 00101 } 00102 00103 00104 00105 void Plane::xz_plane (const Real ypos) 00106 { 00107 const Point p (0., ypos, 0.); 00108 const Point n (0., 1., 0.); 00109 00110 _point = p; 00111 _normal = n; 00112 } 00113 00114 00115 00116 void Plane::yz_plane (const Real xpos) 00117 { 00118 const Point p (xpos, 0., 0.); 00119 const Point n (1., 0., 0.); 00120 00121 _point = p; 00122 _normal = n; 00123 } 00124 00125 00126 00127 bool Plane::above_surface (const Point& p) const 00128 { 00129 // Create a vector from the surface to point p; 00130 const Point w = p - _point; 00131 00132 // The point is above the surface if the projection 00133 // of that vector onto the normal is positive 00134 const Real proj = w*this->normal(); 00135 00136 if (proj > 0.) 00137 return true; 00138 00139 return false; 00140 } 00141 00142 00143 00144 bool Plane::below_surface (const Point& p) const 00145 { 00146 return ( !this->above_surface (p) ); 00147 } 00148 00149 00150 00151 bool Plane::on_surface (const Point& p) const 00152 { 00153 // Create a vector from the surface to point p; 00154 const Point w = p - _point; 00155 00156 // If the projection of that vector onto the 00157 // plane's normal is 0 then the point is in 00158 // the plane. 00159 const Real proj = w * this->normal(); 00160 00161 if (std::abs(proj) < 1.e-10) 00162 return true; 00163 00164 return false; 00165 } 00166 00167 00168 00169 Point Plane::closest_point (const Point& p) const 00170 { 00171 // Create a vector from the surface to point p; 00172 const Point w = p - _point; 00173 00174 // The closest point in the plane to point p 00175 // is in the negative normal direction 00176 // a distance w (dot) p. 00177 const Point cp = p - this->normal()*(w*this->normal()); 00178 00179 return cp; 00180 } 00181 00182 00183 00184 Point Plane::unit_normal (const Point&) const 00185 { 00186 return _normal; 00187 } 00188 00189 const Point & Plane::get_planar_point() const 00190 { 00191 return _point; 00192 } 00193 00194 } // namespace libMesh