9/2/2023 0 Comments F solve matlab![]() OK, now we'll draw the resulting lines on top of the triangles we had earlier. Next we use the 3-row with nan trick I described in this post to convert those pairs of vertices into one line object. (r(overt(:,3)) - r(overt(:,1))) Īnd then use those to do the linear interpolation to compute the position where the edge crosses the cylinder like this: uverts = repmat((1-u),).*hel.vertices(overt(:,1),:) + repmat(u,).*hel.vertices(overt(:,2),:) ![]() We've already computed the radius at each vertex, so we can compute u & v parameters for linear interpolation like this: u = (cylrad - r(overt(:,1))). Next we need to calculate where each of those two edges of the triangle cross the cylinder. I'm sure there's a cleaner way to do this, but here's what I came up with. We want to draw a line between the edges of the triangles which connect the vertex with the 0 with each of the two vertices with a 1. Each row of out_vert contains one 0 and two 1's. That way we only have to deal with one type of triangle. So at this point we'll simplify things by flipping all of the 1-out triangles around so that they look like 2-out triangles. ![]() The math for calculating the intersection actually involves terms which cancel out so that the calculation for the 1-out and 2-out triangles look the same. Now we need to take each of those triangles and turn it into a line segment which shows the intersection. If we zoom in we can see that we have a thin band of triangles which go around the part of the surface which crosses the cylinder. claĬt = patch( 'Vertices',hel.vertices, 'Faces',crossing_tris, 'EdgeColor', 'FaceColor',) Let's take a quicky look at those triangles. These are the triangles we're interested in. If the number of outside vertices is 1 or 2, then the triangle crosses the cylinder. This means that they can't contribute to the intersection curve. That's because those triangles are completely inside or completely outside the cylinder. If the number of outside vertices is 0 or 3, then we don't care about the triangle. r = sqrt(hel.vertices(:,1).^2 + hel.vertices(:,2).^2) įor each triangle, count the number of vertices which are outside the cylinder. To do that, we just need to compute the radius for each vertex, and then compare that to 1. Let's walk through that approach in detail.įirst we take the vertices we got from the isosurface, and create a logical mask of all of the vertices which are outside the cylinder. The first two approaches can be fairly involved in some cases, but the third approach generally isn't too hard to implement.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |