Determining if a point is on a face in Ansys Mechanical Scripting / ACT

Nick Ramseyer
Nick Ramseyer Member Posts: 25
10 Comments Name Dropper
**

Hello! I am currently working on an ACT script where I would like to perform a check of many different points to determine if they are on a specific face.

I have investigating two ways of doing this:

Method 1: I have used Ray Casting to cast a ray back on to the face geometry and checked if the face was hit. This method works well; however it appears that the act of casting a ray is very "Slow" such that as soon as this is put into a loop it is no longer usable.

`
def check_if_point_is_on_face(point, face):

face_param = face.ParamAtPoint(point)
normal_vec = face.NormalAtParam(*face_param)
inward_vec = -Vector3D(*normal_vec)
shifted_point = shift_point_along_unit_vector(point, normal_vec, 0.001)
a_point = Point(list(shifted_point), 'm')
a_bound_vector = Ansys.Mechanical.Math.BoundVector(a_point, inward_vec)
cast_settings = Ansys.Mechanical.Selection.GeometryRayCastSettings()
cast_settings.MaxHits = 1
geom_hit = Ansys.Mechanical.Selection.SelectionHelper.CastRayOnGeometry(a_bound_vector, cast_settings)
if len(geom_hit) == 1:
    if geom_hit[0].Entity.Id == face.Id:
        return True
return False`

Method 2: I tried using a bounding box check but quickly ran into mixed results when testing on curved geometries such as this:

Using ParamAtPoint and PointAtParam handle projections very efficiently, however it is also possible for the projection to end up "not on the face". In the example image above all 3 points shown would have the same Param (u,v) for the selected green face, so it isn't performing a check to see if the point is actually on the face.

If anyone has any ideas for how to speed up ray casting or use point projection more efficiently in Mechanical I would greatly appreciate it!

Thank you for your time!

Answers