@@ -132,6 +132,40 @@ class CollisionStencil {
132132 return compute_coefficients (dof (vertices, edges, faces));
133133 }
134134
135+ // / @brief Compute the normal of the stencil.
136+ // / @param vertices Collision mesh vertices
137+ // / @param edges Collision mesh edges
138+ // / @param faces Collision mesh faces
139+ // / @param flip_if_negative If true, flip the normal if the point is on the negative side.
140+ // / @param sign If not nullptr, set to the sign of the normal before any flipping.
141+ // / @return Normal of the stencil.
142+ VectorMax3d compute_normal (
143+ Eigen::ConstRef<Eigen::MatrixXd> vertices,
144+ Eigen::ConstRef<Eigen::MatrixXi> edges,
145+ Eigen::ConstRef<Eigen::MatrixXi> faces,
146+ const bool flip_if_negative = true ,
147+ double * sign = nullptr ) const
148+ {
149+ return compute_normal (
150+ dof (vertices, edges, faces), flip_if_negative, sign);
151+ }
152+
153+ // / @brief Compute the Jacobian of the normal of the stencil.
154+ // / @param vertices Collision mesh vertices
155+ // / @param edges Collision mesh edges
156+ // / @param faces Collision mesh faces
157+ // / @param flip_if_negative If true, flip the normal if the point is on the negative side.
158+ // / @return Jacobian of the normal of the stencil.
159+ MatrixMax<double , 3 , 12 > compute_normal_jacobian (
160+ Eigen::ConstRef<Eigen::MatrixXd> vertices,
161+ Eigen::ConstRef<Eigen::MatrixXi> edges,
162+ Eigen::ConstRef<Eigen::MatrixXi> faces,
163+ const bool flip_if_negative = true ) const
164+ {
165+ return compute_normal_jacobian (
166+ dof (vertices, edges, faces), flip_if_negative);
167+ }
168+
135169 // ----------------------------------------------------------------------
136170 // NOTE: The following functions take stencil vertices as output by dof()
137171 // ----------------------------------------------------------------------
@@ -163,6 +197,24 @@ class CollisionStencil {
163197 virtual VectorMax4d
164198 compute_coefficients (Eigen::ConstRef<VectorMax12d> positions) const = 0 ;
165199
200+ // / @brief Compute the normal of the stencil.
201+ // / @param positions Stencil's vertex positions.
202+ // / @param flip_if_negative If true, flip the normal if the point is on the negative side.
203+ // / @param sign If not nullptr, set to the sign of the normal before any flipping.
204+ // / @return Normal of the stencil.
205+ VectorMax3d compute_normal (
206+ Eigen::ConstRef<VectorMax12d> positions,
207+ bool flip_if_negative = true ,
208+ double * sign = nullptr ) const ;
209+
210+ // / @brief Compute the Jacobian of the normal of the stencil.
211+ // / @param positions Stencil's vertex positions.
212+ // / @param flip_if_negative If true, flip the normal if the point is on the negative side.
213+ // / @return Jacobian of the normal of the stencil.
214+ MatrixMax<double , 3 , 12 > compute_normal_jacobian (
215+ Eigen::ConstRef<VectorMax12d> positions,
216+ bool flip_if_negative = true ) const ;
217+
166218 // / @brief Perform narrow-phase CCD on the candidate.
167219 // / @param[in] vertices_t0 Stencil vertices at the start of the time step.
168220 // / @param[in] vertices_t1 Stencil vertices at the end of the time step.
@@ -189,6 +241,19 @@ class CollisionStencil {
189241 std::ostream& out,
190242 Eigen::ConstRef<VectorMax12d> vertices_t0,
191243 Eigen::ConstRef<VectorMax12d> vertices_t1) const ;
244+
245+ protected:
246+ // / @brief Compute the unnormalized normal of the stencil.
247+ // / @param positions Stencil's vertex positions.
248+ // / @return Unnormalized normal of the stencil.
249+ virtual VectorMax3d compute_unnormalized_normal (
250+ Eigen::ConstRef<VectorMax12d> positions) const = 0;
251+
252+ // / @brief Compute the Jacobian of the unnormalized normal of the stencil.
253+ // / @param positions Stencil's vertex positions.
254+ // / @return Jacobian of the unnormalized normal of the stencil.
255+ virtual MatrixMax<double , 3 , 12 > compute_unnormalized_normal_jacobian (
256+ Eigen::ConstRef<VectorMax12d> positions) const = 0;
192257};
193258
194259} // namespace ipc
0 commit comments