2
$\begingroup$

I am very new with the use of 3D graphics in Mathematica, so my question might be very naive. I need to Import an STL file, apply transformations to it (rotation and translation), and export it back to an STL file.

I have seen the STL-related questions already posted, but they don’t seem to help me. It’s not just the visualisation of the 3D graphics that I need to rotate, but the entire set of facets, with respect to the origin.

Please let me know if I need to clarify things, or provide more details.

$\endgroup$
  • 1
    $\begingroup$ Very briefly: after importing your *. stl file as Import[filename, "GraphicsComplex"], apply RotationTransform[]/TranslationTransform[] to the point list in the first argument of GraphicsComplex[], and then export Graphics3D[GraphicsComplex[newpoints, otherstuff]]. $\endgroup$ – J. M. will be back soon Jul 28 '15 at 2:34
1
$\begingroup$

In version 10.2 (perhaps going back to 10.0, but I cannot verify that), by default STL's are imported as MeshRegion objects. Assuming that casefn is a string representing the path to an STL file, you can see all the elements available for import from the file

Import[casefn, "Elements"]
(*{"BinaryFormat", "BoundaryMeshRegion", "Comments", 
"CoordinateTransform", "FacetNormals", "Graphics3D", 
"GraphicsComplex", "MeshRegion", "PolygonCount", "PolygonData", 
"PolygonObjects", "Summary", "VertexData", "VerticalAxis"} )*

If you use the default MeshRegion, then use TransformedRegion with the *Transform family of geometric transform functions to transform the region

case = Import[casefn, "STL"]; 
center = Mean /@ RegionBounds[case]; 
centered = TransformedRegion[case, TranslationTransform[-center]]

of course, you would use RotationTransform for your problem, but shearing, scaling, reflection, and other geometric transforms are also available. Personally, I do not like the default appearance of MeshRegion objects with edges displayed, so I use a different style

MeshRegion[Import[casefn, "STL"], PlotTheme -> "Polygons"]
$\endgroup$
1
$\begingroup$

Here is a quick answer (based on @J.M.'s comment) for a basic rotation:

 STLdata = Import["MyFile.stl", "GraphicsComplex"];

 RotatedSTL = 
   Graphics3D[
     GeometricTransformation[STLdata, RotationTransform[30 Degree, {1, 1, 1}]], Axes -> True]

 Export["MyFileRotated.stl", RotatedSTL, {"STL","BinaryFormat" -> False}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.