Line data Source code
1 : // The libMesh Finite Element Library.
2 : // Copyright (C) 2002-2025 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 :
23 : namespace libMesh
24 : {
25 :
26 :
27 :
28 : // ------------------------------------------------------------
29 : // Plane class member functions
30 0 : Plane::Plane () = default;
31 :
32 :
33 :
34 0 : Plane::Plane (const Point & p,
35 0 : const Point & n)
36 : {
37 0 : this->create_from_point_normal (p, n);
38 0 : }
39 :
40 :
41 :
42 0 : Plane::Plane (const Point & p0,
43 : const Point & p1,
44 0 : const Point & p2)
45 : {
46 0 : this->create_from_three_points (p0, p1, p2);
47 0 : }
48 :
49 :
50 :
51 0 : Plane::Plane (const Plane & other_plane) :
52 0 : Surface()
53 : {
54 0 : this->create_from_point_normal(other_plane._point,
55 0 : other_plane._normal);
56 0 : }
57 :
58 :
59 :
60 0 : Plane::~Plane () = default;
61 :
62 :
63 :
64 0 : void Plane::create_from_point_normal (const Point & p, const Point & n)
65 : {
66 0 : _normal = n.unit();
67 0 : _point = p;
68 0 : }
69 :
70 :
71 :
72 0 : void Plane::create_from_three_points (const Point & p0,
73 : const Point & p1,
74 : const Point & p2)
75 : {
76 : // Just use p0 for the point.
77 0 : _point = p0;
78 :
79 0 : const Point e0 = p1 - p0;
80 0 : const Point e1 = p2 - p0;
81 0 : const Point n = e0.cross(e1);
82 :
83 0 : _normal = n.unit();
84 0 : }
85 :
86 :
87 :
88 0 : void Plane::xy_plane (const Real zpos)
89 : {
90 0 : const Point p (0., 0., zpos);
91 0 : const Point n (0., 0., 1.);
92 :
93 0 : _point = p;
94 0 : _normal = n;
95 0 : }
96 :
97 :
98 :
99 0 : void Plane::xz_plane (const Real ypos)
100 : {
101 0 : const Point p (0., ypos, 0.);
102 0 : const Point n (0., 1., 0.);
103 :
104 0 : _point = p;
105 0 : _normal = n;
106 0 : }
107 :
108 :
109 :
110 0 : void Plane::yz_plane (const Real xpos)
111 : {
112 0 : const Point p (xpos, 0., 0.);
113 0 : const Point n (1., 0., 0.);
114 :
115 0 : _point = p;
116 0 : _normal = n;
117 0 : }
118 :
119 :
120 :
121 0 : bool Plane::above_surface (const Point & p) const
122 : {
123 : // Create a vector from the surface to point p;
124 0 : 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 0 : const Real proj = w*this->normal();
129 :
130 0 : if (proj > 0.)
131 0 : return true;
132 :
133 0 : return false;
134 : }
135 :
136 :
137 :
138 0 : bool Plane::below_surface (const Point & p) const
139 : {
140 0 : return ( !this->above_surface (p) );
141 : }
142 :
143 :
144 :
145 0 : bool Plane::on_surface (const Point & p) const
146 : {
147 : // Create a vector from the surface to point p;
148 0 : 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 0 : const Real proj = w * this->normal();
154 :
155 0 : if (std::abs(proj) < 1.e-10)
156 0 : return true;
157 :
158 0 : return false;
159 : }
160 :
161 :
162 :
163 0 : Point Plane::closest_point (const Point & p) const
164 : {
165 : // Create a vector from the surface to point p;
166 0 : 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 0 : const Point cp = p - this->normal()*(w*this->normal());
172 :
173 0 : return cp;
174 : }
175 :
176 :
177 :
178 0 : Point Plane::unit_normal (const Point &) const
179 : {
180 0 : return _normal;
181 : }
182 :
183 0 : const Point & Plane::get_planar_point() const
184 : {
185 0 : return _point;
186 : }
187 :
188 : } // namespace libMesh
|