Importing DXF and Manipulating Files with Mathematica

Asked

Viewed 43 times

2

I have five DXF files with various geometric figures.

enter image description here

Are squares with a different geometric shape in each DXF file ...

Four DXF files have a square with a different geometric shape on one side, as shown above.

(DXF1,DXF2,DXF3,DXF4,DXF5)

  1. It is possible to join these 5 files?

enter image description here

  1. Some files are in the wrong position to be mounted, it is possible to rotate them?

  2. Is it possible to create a code that can recognize these geometries and do some editing like this? The animation is just illustrative. It was created only to facilitate understanding.

Animated gif

1 answer

1


ReplaceList[MeshPrimitives[#, 2] & /@ meshes, {___,
    {a : Polygon[{___, ap : Repeated[_, {3}], ___}]}, ___,
    {b : Polygon[{___, bp : Repeated[_, {3}], ___}]}, ___} :>
   Module[{err, trans},
    {err, trans} = 
     Chop[FindGeometricTransform[{ap}, Reverse@{bp}, 
       TransformationClass -> "Rigid", Method -> "Linear"], 0.001];
    {Property[a \[DirectedEdge] b, "trans" -> trans],
      Property[b \[DirectedEdge] a, "trans" -> InverseFunction@trans]} /;
     err < 1 && 
      Quiet@Area[
         RegionIntersection[BoundaryDiscretizeRegion@a, 
          BoundaryDiscretizeRegion@TransformedRegion[b, trans]]] < 1]] //
 With[{g = Graph@Flatten@#},
   Graphics[{FaceForm[], EdgeForm@Thick, First@VertexList@g,
     GeometricTransformation[#,
        Composition @@ (PropertyValue[{g, DirectedEdge @@ #}, "trans"] & /@ 
           Partition[FindShortestPath[g, First@VertexList@g, #], 2, 1])] & /@
      Rest@VertexList@g}]] &

enter image description here

Browser other questions tagged

You are not signed in. Login or sign up in order to post.