1 #ifndef VTESTBED_GEOMETRY_PLANE_HH 2 #define VTESTBED_GEOMETRY_PLANE_HH 6 #include <vtestbed/geometry/math.hh> 7 #include <vtestbed/geometry/plane_position.hh> 8 #include <vtestbed/geometry/ray.hh> 9 #include <vtestbed/geometry/types.hh> 27 template <
class T,
int N>
31 static constexpr
const int dimensions = N;
32 using scalar_type = T;
33 using value_type = Vertex<T,N>;
34 using reference = value_type&;
35 using const_reference =
const value_type&;
38 value_type _normal{T{}};
39 value_type _origin{T{}};
64 Plane(const_reference a, const_reference b, const_reference c);
67 inline const_reference
normal()
const {
return this->_normal; }
70 inline const_reference
origin()
const {
return this->_origin; }
73 inline void invert() { this->_normal = -this->_normal; }
162 template <
class T,
int N>
172 template <
class T,
int N>
175 T num = dot(plane.
origin() - ray.origin(), plane.
normal());
176 T den = dot(ray.direction(), plane.
normal());
177 return ray.origin() + ray.direction() * num / den;
180 template <
class T,
int N>
181 inline Plane_position
182 compare(
const Plane<T,N> plane,
const Vertex<T,N>& point, T eps) {
184 if (t < -eps) {
return Plane_position::Back; }
185 else if (t > eps) {
return Plane_position::Front; }
186 else {
return Plane_position::Same; }
189 template <
class T,
int N>
190 inline Plane_position
191 compare(
const Plane<T,N> lhs,
const Plane<T,N>& rhs, T eps) {
192 T t = dot(lhs.normal(), rhs.normal());
193 if (t < -eps) {
return Plane_position::Back; }
194 else if (t > eps) {
return Plane_position::Front; }
195 else {
return Plane_position::Same; }
202 #endif // vim:filetype=cpp const_reference normal() const
A vector that is orthogonal to the plane.
Coordinate_system< T, N > coordinate_system() const
Coordinate system defined by the and the origin.
Basis< T, N > basis() const
Vector basis for the coordinate system defined by the and the origin.
void invert()
Invert plane orientation (the direction of the normal).
const_reference origin() const
A point on the plane.
int redundant_dimension() const
The index of dimension that has nought basis vector.
value_type project_vector(const_reference vector) const
Project vector on the plane.
T operator()() const
Substitute nought into the plane equation to get .
T operator()(const_reference point) const
Substitute point p to the plane equation.
Three- and two-dimensional plane.
value_type project(const_reference point) const
Project point on the plane.
Vertex< T, N > intersection(const Ray< T, N > &ray, const Plane< T, N > &plane)
Returns intersection point of ray and plane. Edge cases are ignored.