Hi Locklin,
Here's how you can obtain the vertex indices and compute the normal vector for an exterior edge of a pde tet mesh at a point using "DiscreteGeometry" objects:
1. Accessing Vertices from Face ID:
"DiscreteGeometry" doesn't directly provide a function to get vertex indices from a face ID. However, you can achieve this by
- Getting the list of all edges associated with the face ("faceEdges").
- For each edge in the face, use "model.Geometry.edges{edgeID}" to access the edge object and then extract the two vertex indices ("vertex1" and "vertex2") from the edge object.
2. Computing Face Normals:
Once you have the vertex indices for each face, you can compute the face normal vector:
- Calculate the vector difference between two vertices of the face.
- Calculate the cross product of two such vectors (from different edges of the face) to get the normal vector by using the "cross" function.
- Normalize the resulting vector to ensure unit length.
function norms = meshnormals(model,contactPoints)
norms = zeros(size(contactPoints));
for i = 1:size(contactPoints(1,:))
edge = nearestEdge(model.Geometry,contactPoints(i,:));
faces = facesAttachedToEdges(model.Geometry,edge,'external');
faceEdges = model.Geometry.faces{faceID};
edge = model.Geometry.edges{edgeID};
faceNormal = cross(model.Geometry.vertices{vertex1} - model.Geometry.vertices{vertex2}, ...
model.Geometry.vertices{anotherVertex} - model.Geometry.vertices{vertex2});
faceNormal = faceNormal / norm(faceNormal);
faceNormals = [faceNormals; faceNormal];
edgeNormal = mean(faceNormals, 1);
Here are some links that you could refer to for any additional information: