I have two surfaces, representing the inner and outer surface of a skull. To calculate the thickness, I thought about calculating the length of each inner surface's vertex normal for the vertex until it crosses the outer surface. I'm trying to use these fantastic functions: https://docs.blender.org/api/blender_python_api_current/mathutils.geometry.html
You can take a look at the surfaces here:
Any help will be most welcome! Thanks, Noam
***** Edit ******
I tried to use ray_cast as @batFINGER suggested. I might do something wrong, but it gives me strange results:
inner_skull = bpy.data.objects['inner_skull']
vert = inner_skull.data.vertices[0]
hit, loc, norm, face = inner_skull.ray_cast(vert.co, vert.normal)
I ran this code after making sure all the normals are pointing outside. That gave me the same vertice pos as the hit location. So I tried to add the normal to the starting point:
hit, loc, norm, face = inner_skull.ray_cast(vert.co + vert.normal, vert.normal)
That gave me no hit at all. (I check and vert.co + vert.normal doesn't cross the outer skull)
Any suggestions?
***** Edit 2 *****
I ended up using the following code, which is really not optimized, but does work:
def check_vert_intersections(vert, surf_obj):
for face_ind, face in enumerate(surf_obj.data.polygons):
face_verts = [surf_obj.data.vertices[vert].co for vert in face.vertices]
intersection_point = mathutils.geometry.intersect_ray_tri(
face_verts[0], face_verts[1], face_verts[2], vert.normal, vert.co, True)
if intersection_point is not None:
return intersection_point, face_ind
return None, -1
***** Edit 3 *****
I used @batFINGER solution and it's great! I've just changed the loop to go over the vertices and not the faces, because I needed the thickness to be calculated for each vertice. You can see a video of the solution here: https://www.dropbox.com/s/xik3ucmnc94qaba/skull_points_thickness.mp4?dl=0
vert.co
and-vert.normal
as ray origin and direction respectively, from inner to outer or vice versa. $\endgroup$check_vert_intersections
will "work" as long as each objects matrix_world is identity (and maybe same) otherwise need to make compensation of local coordinate space of one to other. Your attempt atray_cast
was from inner_skull out from a vertex normal to inner_skull. Hence the lack of a result. $\endgroup$