CMSC23740 Common Code Library
Support code for CS23740 programming projects
Toggle main menu visibility
Loading...
Searching...
No Matches
plane.hpp
Go to the documentation of this file.
1
7
8
/* COPYRIGHT (c) 2026 John Reppy (https://cs.uchicago.edu/~jhr)
9
* All rights reserved.
10
*/
11
12
#ifndef _CS237_PLANE_HPP_
13
#define _CS237_PLANE_HPP_
14
15
#ifndef _CS237_HPP_
16
#error "cs237/plane.hpp should not be included directly"
17
#endif
18
19
namespace
cs237
{
20
21
namespace
__detail
{
22
24
template
<
typename
T>
25
struct
Plane
{
26
using
vec3
= glm::vec<3, T, glm::defaultp>;
27
using
vec4
= glm::vec<4, T, glm::defaultp>;
28
29
vec4
_nd
;
30
31
Plane
() { }
32
37
Plane
(
vec3
n, T d) :
_nd
(
vec4
(n, T(d))) { }
38
42
Plane
(
vec3
n,
vec3
p)
43
{
44
vec3
norm
= glm::normalize(n);
45
double
d = -glm::dot(
norm
, p);
46
this->_nd =
vec4
(
norm
, d);
47
}
48
50
vec3
norm
()
const
{
return
vec3
(this->_nd); }
51
53
T
dist
()
const
{
return
this->_nd.w; }
54
58
T
distanceToPt
(
vec3
const
&p)
const
59
{
60
return
glm::dot(this->_nd,
vec4
(p, 1.0));
61
}
62
66
vec3
project
(
vec3
const
&p)
const
67
{
68
return
p - this->
distanceToPt
(p) * this->
norm
();
69
}
70
72
std::string
toString
()
const
73
{
74
return
"Plane("
+ glm::to_string(this->
norm
()) +
", "
75
+
to_string
(this->
dist
()) +
")"
;
76
}
77
78
};
79
80
/***** Output *****/
81
82
template
<
typename
T>
83
inline
std::ostream&
operator<<
(std::ostream& s,
Plane<T>
const
&plane)
84
{
85
return
(s << plane.
toString
());
86
}
87
88
}
// namespace __detail
89
91
using
Planef_t
=
__detail::Plane<float>
;
93
using
Planed_t
=
__detail::Plane<double>
;
94
95
}
// namespace cs237
96
97
#endif
// !_CS237_PLANE_HPP_
cs237::__detail
Definition
aabb.hpp:24
cs237::__detail::operator<<
std::ostream & operator<<(std::ostream &s, __detail::AABB< T > const &bb)
print the axis-aligned bounding box to the output stream
cs237
Definition
aabb.hpp:22
cs237::Planed_t
__detail::Plane< double > Planed_t
Double-precision planes.
Definition
plane.hpp:93
cs237::Planef_t
__detail::Plane< float > Planef_t
Single-precision planes.
Definition
plane.hpp:91
cs237::to_string
std::string to_string(Channels ch)
convert a Channels value to a printable string
cs237::__detail::Plane
representation of a oriented 3D plane
Definition
plane.hpp:25
cs237::__detail::Plane::vec3
glm::vec< 3, T, glm::defaultp > vec3
Definition
plane.hpp:26
cs237::__detail::Plane::toString
std::string toString() const
the string representation of a plane
Definition
plane.hpp:72
cs237::__detail::Plane::vec4
glm::vec< 4, T, glm::defaultp > vec4
Definition
plane.hpp:27
cs237::__detail::Plane::Plane
Plane()
unit normal and signed distance from origin
Definition
plane.hpp:31
cs237::__detail::Plane< float >::_nd
vec4 _nd
Definition
plane.hpp:29
cs237::__detail::Plane::Plane
Plane(vec3 n, T d)
specify a plane as a unit-length normal vector and signed distance from origin
Definition
plane.hpp:37
cs237::__detail::Plane::dist
T dist() const
signed distance from origin to plane
Definition
plane.hpp:53
cs237::__detail::Plane::distanceToPt
T distanceToPt(vec3 const &p) const
signed distance from a point to plane
Definition
plane.hpp:58
cs237::__detail::Plane< float >::norm
vec3 norm() const
Definition
plane.hpp:50
cs237::__detail::Plane::project
vec3 project(vec3 const &p) const
Definition
plane.hpp:66
cs237::__detail::Plane::Plane
Plane(vec3 n, vec3 p)
specify a plane as a normal vector and point on the plane
Definition
plane.hpp:42
cs237-library
include
cs237
plane.hpp
Generated by
1.18.0