Skip to content

Nuts_and_bolts

Munther Hindi edited this page Sep 2, 2024 · 2 revisions

Sample Nuts and bolts

Nuts, bolts and other fasteners can be added to a FreeCAD document using the external Fasteners Workbench Fasteners

The Workbench can be installed, as usual, using the FreeCAD Addon Manager.

An example screenshot showing four identical bolts, but placed and rotated differently, as they appear in the FreeCAD document (left) and as displayed in the load_gdml_color application (right)

Bolts

The FreeCAD file can be downloaded from here duplicated bolts

An example screenshot showing duplicated nuts is shown as they appear in the FreeCAD document (left) and as displayed in the load_gdml_color application (right) Nuts

The FreeCAD file can be downloaded from here duplicated nuts

Technical Note

Because tessellations can produce a large number of faces, and hence a large gdml file, the exporter tries to cache in the exported Shape (a FreeCAD object) and just uses a reference to the already exported tessellation, rather than create a new one, once the same Shape is encountered. Thus for the duplicated bolts and nuts shown in the examples above, only _one_tessellation was exported and only the different positions and rotations were added to the file. Because there could potentially be a large number of Shape providers, we do not test each Shape for its type to see what kind of Shape it is when determining if it has been exported or not. Rather, we rely on the following tests to decide if a new tessellation should be exported for a Shape:

  1. Compare the volumes of the Shapes. If they are not equal, then the Shapes are not the same

  2. Each Shape has a number of accessible vertexes (via Shape.Vertexes). If the number of vertexes is not the same (as any of the cached Shapes), then a new tessellation is exported.

  3. Compute the mean position of the vertexes. If the mean position differs from that of all the cached shapes, then a new tessellation is exported.

  4. Compute the second moments of vertexes about the three axes:

    $$I_{xx} = \sum_i (y_i^2 + z_i^2)$$

    $$I_{yy} = \sum_i (x_i^2 + z_i^2)$$

    $$I_{zz} = \sum_i (x_i^2 + x_i^2)$$

    If any of the moments differs from the those of all the cached shapes, then a new tessellation is exported.

I (Munther Hindi, the author of the AutoTessellateExporter) believe that the above tests are sufficient to determine whether a shape has been exported or not. However, I am unaware of any mathematical proof that guarantees that different shapes will differ in the above geometric criteria. The extreme, but guaranteed, test would be to compare the location of every vertex in one Shape, with the locations of the vertexes in the cached shapes. However, since there is no guarantee that vertexes in two shapes are ordered in the same way, potentially once has to compare every point in one shape, with every point in the other shape, or else perform some meanningful sort. For a simple threaded M6x30 mm bolt, there are 96 vertexes, so potentially when every new bolt is encountered, 10,000 comparisons might have to be made. In the particular case of nuts and bolts, it is actually quite likely that there are 10's, if not 100's of bolts/nuts, in the document, especially if the document came from an engineering, rather than a physics, design. Therefore, if the point-by-point test came after the object passed all the above tests, it is likely that the time-consuming, exhastive test has to be done more often than not. Instead, we assume that if the shape passed all of the above tests, then it is likely to be the same shape and hence that the points are ordered in the same way. Therefore, we only conduct the following additional test, which is linear in time with the number of vertexes:

  1. Randomly select 10% of the vertexes of the two shapes being compared and compare the distances between their respective points. If at any point the answer is greater than some threshold (about $10^{-4}$ mm) then the shapes are considered different, if all (of the 10% of points) match then the shapes are considered the same and a reference to the cached shape is used.

If anyone reading this has an example of two shapes that are different but whose vertexes pass the above 5 tests, please let me know!