reverse - Reverse engineering functions

segmentation(mesh, tolerance=5, sharp=0.2) Mesh[source]

Surface segmentation based on curvature. This functions splits faces into groups based on curvature proximity. Ideally each resulting group is a set of faces with the same curvature. In practice such is not possible due to the mesh resolution introducing bias in curvature estimation. Thus a tolerance is used to decide what is a sufficiently close curvature to belong to the same group. In order to avoid too sharp edges to be considered a very low resolution but smooth surface, sharp is the value of the limit edge angle that can be considered in smooth surface.

This function is particularly usefull when importing geometries from a format that doesn’t manage groups (such as STL).

Parameters:
  • tolerance (float) – maximum difference factor between curvatures of a same group (1 means +100% curvature is allowed)
  • sharp (float) – angle above which an angle is always sharp (radians)

Note

This functions is not magic and despite the default parameters are usually fine for mechanical parts, you may get badly grouped faces in some cases, hence you will need to tune the parameters.

The success of this functions is highly dependent of the quality of the input mesh triangulation.

Example

>>> part = read('myfile.stl')
>>> part.mergeclose()
>>> part = segmentation(part)

After importing you generally obtain something like this with all triangles in the same group

../_images/segmentation-before.png

A segmentation will find what to group and give you this

../_images/segmentation-after.png
guesssurface(surface, precision=1e-05, attempt=False)[source]

Guess the surface kind, returns its parameters.

Return a tuple ('surface_type', parameters)

Parameters:
  • surface (Mesh) – mesh from which to find the surface kind
  • precision (float) – typical distance error from mesh to ideal surface in the surface regression
  • attempt (bool) – if True, will not raise an error if the acheived error is too big
guessjoint(solid1, solid2, surface1, surface2, guess=dquat(1, 0, 0, 0), precision=1e-05) joint[source]

Create a kinematic joint based on the surfaces given. The function will use guesssurface to find the surface kind and then deduce the appropriate joint to make the surfaces coincide.

Parameters:
  • solid1 – solids the joint applies on
  • solid2 – solids the joint applies on
  • surface1 – the surface to retreive the joint definition from
  • surface2 – the surface to retreive the joint definition from
  • guess (quat, mat3) – orientation tip to orient properly the joint axis, if there is
  • precision (float) – precision for guesssurface