@@ -29,9 +29,9 @@ template <int LocalDim, int EmbedDim> class HyperPlane {
2929 static constexpr int local_dim = LocalDim;
3030 HyperPlane () = default ;
3131 // constructs a hyperplane passing through 2 points, e.g. a line
32- HyperPlane (const Eigen:: Matrix<double , embed_dim, 1 >& x1, const Eigen:: Matrix<double , embed_dim, 1 >& x2) : p_(x1) {
32+ HyperPlane (const Matrix<double , embed_dim, 1 >& x1, const Matrix<double , embed_dim, 1 >& x2) : p_(x1) {
3333 fdapde_static_assert (local_dim == 1 , THIS_METHOD_IS_ONLY_FOR_LINES);
34- Eigen:: Matrix<double , embed_dim, 1 > tmp = x2 - x1;
34+ Matrix<double , embed_dim, 1 > tmp = x2 - x1;
3535 basis_.col (0 ) = tmp.normalized ();
3636 if constexpr (embed_dim == 2 ) normal_ << -tmp[0 ], tmp[1 ];
3737 if constexpr (embed_dim == 3 ) normal_ << -tmp[0 ], tmp[1 ], 0 ; // one of the (infintely-many) normals to 3D line
@@ -40,28 +40,31 @@ template <int LocalDim, int EmbedDim> class HyperPlane {
4040 }
4141 // constructs an hyperplane passing through 3 (non-collinear) points, e.g. a plane
4242 HyperPlane (
43- const Eigen:: Matrix<double , embed_dim, 1 >& x1, const Eigen:: Matrix<double , embed_dim, 1 >& x2,
44- const Eigen:: Matrix<double , embed_dim, 1 >& x3) :
43+ const Matrix<double , embed_dim, 1 >& x1, const Matrix<double , embed_dim, 1 >& x2,
44+ const Matrix<double , embed_dim, 1 >& x3) :
4545 p_ (x1) {
4646 fdapde_static_assert (local_dim == 2 , THIS_METHOD_IS_ONLY_FOR_PLANES);
4747 basis_.col (0 ) = (x2 - x1).normalized ();
48- basis_.col (1 ) = ((x3 - x1) - orthogonal_project (
49- Eigen::Matrix< double , embed_dim, 1 >( x3 - x1),
50- Eigen:: Matrix<double , embed_dim, 1 >(basis_.col (0 ))))
51- .normalized ();
48+ basis_.col (1 ) =
49+ (( x3 - x1) -
50+ orthogonal_project (Matrix< double , embed_dim, 1 >(x3 - x1), Matrix<double , embed_dim, 1 >(basis_.col (0 ))))
51+ .normalized ();
5252 normal_ = ((x2 - x1).cross (x3 - x1)).normalized ();
5353 offset_ = -x1.dot (normal_);
5454 }
5555 // constructors from matrix coordinates
56- HyperPlane (const Eigen::Matrix<double , embed_dim, 2 >& coords) requires (local_dim == 1 ) :
57- HyperPlane (coords.col(0 ), coords.col(1 )) { }
58- HyperPlane (const Eigen::Matrix<double , embed_dim, 3 >& coords) requires (local_dim == 2 ) :
59- HyperPlane (coords.col(0 ), coords.col(1 ), coords.col(2 )) { }
56+ HyperPlane (const Matrix<double , embed_dim, 2 >& coords)
57+ requires (local_dim == 1 )
58+ : HyperPlane(coords.col(0 ), coords.col(1 )) { }
59+ HyperPlane (const Matrix<double , embed_dim, 3 >& coords)
60+ requires (local_dim == 2 )
61+ : HyperPlane(coords.col(0 ), coords.col(1 ), coords.col(2 )) { }
6062 // general hyperplane constructor
61- HyperPlane (const Eigen::Matrix<double , embed_dim, local_dim + 1 >& coords) requires (local_dim > 2 ) :
62- p_ (coords.col(0 )) {
63+ HyperPlane (const Matrix<double , embed_dim, local_dim + 1 >& coords)
64+ requires (local_dim > 2 )
65+ : p_(coords.col(0 )) {
6366 basis_ = coords.rightCols (local_dim).colwise () - coords.col (0 );
64- // basis orthonormalization via modified Gram-Schmidt method
67+ // basis orthonormalization via modified Gram-Schmidt method
6568 basis_.col (0 ) /= basis_.col (0 ).norm ();
6669 for (int i = 1 ; i < local_dim; ++i) {
6770 for (int j = 0 ; j < i; ++j) {
@@ -73,46 +76,43 @@ template <int LocalDim, int EmbedDim> class HyperPlane {
7376 offset_ = -coords.col (0 ).dot (normal_);
7477 }
7578 // projection
76- Eigen:: Matrix<double , local_dim, 1 > project_onto (const Eigen:: Matrix<double , embed_dim, 1 >& x) {
79+ Matrix<double , local_dim, 1 > project_onto (const Matrix<double , embed_dim, 1 >& x) {
7780 if constexpr (local_dim == embed_dim) {
7881 return x;
7982 } else {
8083 // build the projection onto the space spanned by basis_
81- Eigen:: Matrix<double , local_dim, 1 > proj;
84+ Matrix<double , local_dim, 1 > proj;
8285 for (int i = 0 ; i < local_dim; ++i) { proj[i] = (x - p_).dot (basis_.col (i)); }
8386 return proj;
8487 }
8588 }
86- Eigen:: Matrix<double , embed_dim, 1 > project (const Eigen:: Matrix<double , embed_dim, 1 >& x) const {
89+ Matrix<double , embed_dim, 1 > project (const Matrix<double , embed_dim, 1 >& x) const {
8790 if constexpr (local_dim == embed_dim) {
8891 return x;
8992 } else {
9093 return basis_ * basis_.transpose () * (x - p_) + p_;
9194 }
9295 }
93- double distance (const Eigen::Matrix<double , embed_dim, 1 >& x) {
94- return (x - project (x)).norm ();
95- } // point-plane distance
96- double eval (const Eigen::Matrix<double , embed_dim, 1 >& coeffs) const { return normal_.dot (coeffs) + offset_; }
97- Eigen::Matrix<double , embed_dim, 1 > operator ()(const Eigen::Matrix<double , local_dim, 1 >& coeffs) const {
98- Eigen::Matrix<double , embed_dim, 1 > res = p_;
96+ double distance (const Matrix<double , embed_dim, 1 >& x) { return (x - project (x)).norm (); } // point-plane distance
97+ double eval (const Matrix<double , embed_dim, 1 >& coeffs) const { return normal_.dot (coeffs) + offset_; }
98+ Matrix<double , embed_dim, 1 > operator ()(const Matrix<double , local_dim, 1 >& coeffs) const {
99+ Matrix<double , embed_dim, 1 > res = p_;
99100 for (int i = 0 ; i < local_dim; ++i) { res += coeffs[i] * basis_.col (i); }
100101 return res;
101102 }
102- const Eigen:: Matrix<double , embed_dim, 1 >& normal () const { return normal_; } // plane normal direction
103- const Eigen:: Matrix<double , embed_dim, 1 >& point () const { return p_; } // a point belonging to the plane
104- const Eigen:: Matrix<double , embed_dim, local_dim>& basis () const { return basis_; }
103+ const Matrix<double , embed_dim, 1 >& normal () const { return normal_; } // plane normal direction
104+ const Matrix<double , embed_dim, 1 >& point () const { return p_; } // a point belonging to the plane
105+ const Matrix<double , embed_dim, local_dim>& basis () const { return basis_; }
105106 private:
106107 // let x_1, x_2, \ldots, x_{N+1} be a set of N+1 points through which the plane passes
107- Eigen:: Matrix<double , embed_dim, local_dim> basis_; // matrix [x2 - x1, x3 - x1, \ldots, x_{N+1} - x1]
108- Eigen:: Matrix<double , embed_dim, 1 > normal_; // normal vector to the hyperplane
109- Eigen:: Matrix<double , embed_dim, 1 > p_; // point through which the plane is guaranteed to pass
108+ Matrix<double , embed_dim, local_dim> basis_; // matrix [x2 - x1, x3 - x1, \ldots, x_{N+1} - x1]
109+ Matrix<double , embed_dim, 1 > normal_; // normal vector to the hyperplane
110+ Matrix<double , embed_dim, 1 > p_; // point through which the plane is guaranteed to pass
110111 double offset_; // hyperplane's intercept (the d in the equation ax + by + cz + d = 0)
111112
112113 // orthogonal projection of vector v over u
113114 template <int N>
114- constexpr Eigen::Matrix<double , N, 1 >
115- orthogonal_project (const Eigen::Matrix<double , N, 1 >& v, const Eigen::Matrix<double , N, 1 >& u) {
115+ constexpr Matrix<double , N, 1 > orthogonal_project (const Matrix<double , N, 1 >& v, const Matrix<double , N, 1 >& u) {
116116 return (v.dot (u) / u.squaredNorm () * u.array ()).matrix ();
117117 }
118118};
0 commit comments