plane.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 // C++ includes
21 
22 // Local includes
23 #include "libmesh/plane.h"
24 
25 namespace libMesh
26 {
27 
28 
29 
30 // ------------------------------------------------------------
31 // Plane class member functions
33 {
34 }
35 
36 
37 
38 Plane::Plane (const Point & p,
39  const Point & n)
40 {
41  this->create_from_point_normal (p, n);
42 }
43 
44 
45 
46 Plane::Plane (const Point & p0,
47  const Point & p1,
48  const Point & p2)
49 {
50  this->create_from_three_points (p0, p1, p2);
51 }
52 
53 
54 
55 Plane::Plane (const Plane & other_plane) :
56  Surface()
57 {
58  this->create_from_point_normal(other_plane._point,
59  other_plane._normal);
60 }
61 
62 
63 
65 {
66 }
67 
68 
69 
70 void Plane::create_from_point_normal (const Point & p, const Point & n)
71 {
72  _normal = n.unit();
73  _point = p;
74 }
75 
76 
77 
79  const Point & p1,
80  const Point & p2)
81 {
82  // Just use p0 for the point.
83  _point = p0;
84 
85  const Point e0 = p1 - p0;
86  const Point e1 = p2 - p0;
87  const Point n = e0.cross(e1);
88 
89  _normal = n.unit();
90 }
91 
92 
93 
94 void Plane::xy_plane (const Real zpos)
95 {
96  const Point p (0., 0., zpos);
97  const Point n (0., 0., 1.);
98 
99  _point = p;
100  _normal = n;
101 }
102 
103 
104 
105 void Plane::xz_plane (const Real ypos)
106 {
107  const Point p (0., ypos, 0.);
108  const Point n (0., 1., 0.);
109 
110  _point = p;
111  _normal = n;
112 }
113 
114 
115 
116 void Plane::yz_plane (const Real xpos)
117 {
118  const Point p (xpos, 0., 0.);
119  const Point n (1., 0., 0.);
120 
121  _point = p;
122  _normal = n;
123 }
124 
125 
126 
127 bool Plane::above_surface (const Point & p) const
128 {
129  // Create a vector from the surface to point p;
130  const Point w = p - _point;
131 
132  // The point is above the surface if the projection
133  // of that vector onto the normal is positive
134  const Real proj = w*this->normal();
135 
136  if (proj > 0.)
137  return true;
138 
139  return false;
140 }
141 
142 
143 
144 bool Plane::below_surface (const Point & p) const
145 {
146  return ( !this->above_surface (p) );
147 }
148 
149 
150 
151 bool Plane::on_surface (const Point & p) const
152 {
153  // Create a vector from the surface to point p;
154  const Point w = p - _point;
155 
156  // If the projection of that vector onto the
157  // plane's normal is 0 then the point is in
158  // the plane.
159  const Real proj = w * this->normal();
160 
161  if (std::abs(proj) < 1.e-10)
162  return true;
163 
164  return false;
165 }
166 
167 
168 
170 {
171  // Create a vector from the surface to point p;
172  const Point w = p - _point;
173 
174  // The closest point in the plane to point p
175  // is in the negative normal direction
176  // a distance w (dot) p.
177  const Point cp = p - this->normal()*(w*this->normal());
178 
179  return cp;
180 }
181 
182 
183 
185 {
186  return _normal;
187 }
188 
190 {
191  return _point;
192 }
193 
194 } // namespace libMesh
Point _point
Definition: plane.h:144
double abs(double a)
const Point & normal() const
Definition: plane.h:139
void create_from_point_normal(const Point &p, const Point &n)
Definition: plane.C:70
void create_from_three_points(const Point &p0, const Point &p1, const Point &p2)
Definition: plane.C:78
const Point & get_planar_point() const
Definition: plane.C:189
virtual bool above_surface(const Point &p) const override
Definition: plane.C:127
void xy_plane(const Real zpos=0.)
Definition: plane.C:94
TypeVector< T > unit() const
Definition: type_vector.C:37
virtual Point closest_point(const Point &p) const override
Definition: plane.C:169
void yz_plane(const Real xpos=0.)
Definition: plane.C:116
TypeVector< typename CompareTypes< T, T2 >::supertype > cross(const TypeVector< T2 > &v) const
Definition: type_vector.h:882
A geometric object representing a planar surface.
Definition: plane.h:36
virtual bool below_surface(const Point &p) const override
Definition: plane.C:144
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Point _normal
Definition: plane.h:145
Base class for Plane and Sphere classes.
Definition: surface.h:42
virtual Point unit_normal(const Point &p) const override
Definition: plane.C:184
void xz_plane(const Real ypos=0.)
Definition: plane.C:105
A geometric point in (x,y,z) space.
Definition: point.h:38
virtual bool on_surface(const Point &p) const override
Definition: plane.C:151