libMesh
Loading...
Searching...
No Matches
plane.C
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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// Local includes
21#include "libmesh/plane.h"
22
23namespace libMesh
24{
25
26
27
28// ------------------------------------------------------------
29// Plane class member functions
30Plane::Plane () = default;
31
32
33
35 const Point & n)
36{
37 this->create_from_point_normal (p, n);
38}
39
40
41
42Plane::Plane (const Point & p0,
43 const Point & p1,
44 const Point & p2)
45{
46 this->create_from_three_points (p0, p1, p2);
47}
48
49
50
51Plane::Plane (const Plane & other_plane) :
52 Surface()
53{
54 this->create_from_point_normal(other_plane._point,
55 other_plane._normal);
56}
57
58
59
60Plane::~Plane () = default;
61
62
63
64void Plane::create_from_point_normal (const Point & p, const Point & n)
65{
66 _normal = n.unit();
67 _point = p;
68}
69
70
71
73 const Point & p1,
74 const Point & p2)
75{
76 // Just use p0 for the point.
77 _point = p0;
78
79 const Point e0 = p1 - p0;
80 const Point e1 = p2 - p0;
81 const Point n = e0.cross(e1);
82
83 _normal = n.unit();
84}
85
86
87
88void Plane::xy_plane (const Real zpos)
89{
90 const Point p (0., 0., zpos);
91 const Point n (0., 0., 1.);
92
93 _point = p;
94 _normal = n;
95}
96
97
98
99void Plane::xz_plane (const Real ypos)
100{
101 const Point p (0., ypos, 0.);
102 const Point n (0., 1., 0.);
103
104 _point = p;
105 _normal = n;
106}
107
108
109
110void Plane::yz_plane (const Real xpos)
111{
112 const Point p (xpos, 0., 0.);
113 const Point n (1., 0., 0.);
114
115 _point = p;
116 _normal = n;
117}
118
119
120
121bool Plane::above_surface (const Point & p) const
122{
123 // Create a vector from the surface to point p;
124 const Point w = p - _point;
125
126 // The point is above the surface if the projection
127 // of that vector onto the normal is positive
128 const Real proj = w*this->normal();
129
130 if (proj > 0.)
131 return true;
132
133 return false;
134}
135
136
137
138bool Plane::below_surface (const Point & p) const
139{
140 return ( !this->above_surface (p) );
141}
142
143
144
145bool Plane::on_surface (const Point & p) const
146{
147 // Create a vector from the surface to point p;
148 const Point w = p - _point;
149
150 // If the projection of that vector onto the
151 // plane's normal is 0 then the point is in
152 // the plane.
153 const Real proj = w * this->normal();
154
155 if (std::abs(proj) < 1.e-10)
156 return true;
157
158 return false;
159}
160
161
162
164{
165 // Create a vector from the surface to point p;
166 const Point w = p - _point;
167
168 // The closest point in the plane to point p
169 // is in the negative normal direction
170 // a distance w (dot) p.
171 const Point cp = p - this->normal()*(w*this->normal());
172
173 return cp;
174}
175
176
177
179{
180 return _normal;
181}
182
184{
185 return _point;
186}
187
188} // namespace libMesh
This class defines a plane.
Definition plane.h:37
const Point & get_planar_point() const
Definition plane.C:183
Point _normal
Definition plane.h:145
void xz_plane(const Real ypos=0.)
Creates an XZ plane located at y=ypos.
Definition plane.C:99
Point _point
The plane is defined by a point and a normal.
Definition plane.h:144
virtual Point unit_normal(const Point &p) const override
Definition plane.C:178
~Plane()
Destructor.
void yz_plane(const Real xpos=0.)
Creates an YZ plane located at x=xpos.
Definition plane.C:110
void create_from_point_normal(const Point &p, const Point &n)
Defines a plane containing point p with normal n.
Definition plane.C:64
Plane()
Dummy Constructor.
virtual bool on_surface(const Point &p) const override
Definition plane.C:145
virtual bool above_surface(const Point &p) const override
Definition plane.C:121
virtual Point closest_point(const Point &p) const override
Definition plane.C:163
void xy_plane(const Real zpos=0.)
Creates an XY plane located at z=zpos.
Definition plane.C:88
void create_from_three_points(const Point &p0, const Point &p1, const Point &p2)
Defines a plane intersecting the three points p0, p1, and p2.
Definition plane.C:72
virtual bool below_surface(const Point &p) const override
Definition plane.C:138
const Point & normal() const
Definition plane.h:139
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:40
The base class for all "surface" related geometric objects.
Definition surface.h:43
TypeVector< typename CompareTypes< T, T2 >::supertype > cross(const TypeVector< T2 > &v) const
TypeVector< T > unit() const
The libMesh namespace provides an interface to certain functionality in the library.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real