1
$\begingroup$

Say that we have a list of tuples called "data", where

data={{0,0,1.000},{0,10,0.9397},{0,20,0.7660},{0,30,0.5000},{0,40,0.1736},{0,50,0.1736},{0,60,0.5000},{0,70,0.7660},{0,80,0.9397},{0,90,1.000},{0,100,0.9397},{0,110,0.7660},{0,120,0.5000},{0,130,0.1736},{0,140,0.1736},{0,150,0.5000},{0,160,0.7660},{0,170,0.9397},{0,180,1.000},{0,190,0.9397},{0,200,0.7660},{0,210,0.5000},{0,220,0.1736},{0,230,0.1736},{0,240,0.5000},{0,250,0.7660},{0,260,0.9397},{0,270,1.000},{0,280,0.9397},{0,290,0.7660},{0,300,0.5000},{0,310,0.1736},{0,320,0.1736},{0,330,0.5000},{0,340,0.7660},{0,350,0.9397},{0,360,1.000},{10,0,0.9998},{10,10,0.9395},{10,20,0.7659},{10,30,0.4999},{10,40,0.1736},{10,50,0.1736},{10,60,0.4999},{10,70,0.7659},{10,80,0.9395},{10,90,0.9998},{10,100,0.9395},{10,110,0.7659},{10,120,0.4999},{10,130,0.1736},{10,140,0.1736},{10,150,0.4999},{10,160,0.7659},{10,170,0.9395},{10,180,0.9998},{10,190,0.9395},{10,200,0.7659},{10,210,0.4999},{10,220,0.1736},{10,230,0.1736},{10,240,0.4999},{10,250,0.7659},{10,260,0.9395},{10,270,0.9998},{10,280,0.9395},{10,290,0.7659},{10,300,0.4999},{10,310,0.1736},{10,320,0.1736},{10,330,0.4999},{10,340,0.7659},{10,350,0.9395},{10,360,0.9998},{20,0,0.9962},{20,10,0.9361},{20,20,0.7631},{20,30,0.4981},{20,40,0.1729},{20,50,0.1729},{20,60,0.4981},{20,70,0.7631},{20,80,0.9361},{20,90,0.9962},{20,100,0.9361},{20,110,0.7631},{20,120,0.4981},{20,130,0.1729},{20,140,0.1729},{20,150,0.4981},{20,160,0.7631},{20,170,0.9361},{20,180,0.9962},{20,190,0.9361},{20,200,0.7631},{20,210,0.4981},{20,220,0.1729},{20,230,0.1729},{20,240,0.4981},{20,250,0.7631},{20,260,0.9361},{20,270,0.9962},{20,280,0.9361},{20,290,0.7631},{20,300,0.4981},{20,310,0.1729},{20,320,0.1729},{20,330,0.4981},{20,340,0.7631},{20,350,0.9361},{20,360,0.9962},{30,0,0.9803},{30,10,0.9211},{30,20,0.7508},{30,30,0.4898},{30,40,0.1697},{30,50,0.1697},{30,60,0.4898},{30,70,0.7508},{30,80,0.9211},{30,90,0.9803},{30,100,0.9211},{30,110,0.7508},{30,120,0.4898},{30,130,0.1697},{30,140,0.1697},{30,150,0.4898},{30,160,0.7508},{30,170,0.9211},{30,180,0.9803},{30,190,0.9211},{30,200,0.7508},{30,210,0.4898},{30,220,0.1697},{30,230,0.1697},{30,240,0.4898},{30,250,0.7508},{30,260,0.9211},{30,270,0.9803},{30,280,0.9211},{30,290,0.7508},{30,300,0.4898},{30,310,0.1697},{30,320,0.1697},{30,330,0.4898},{30,340,0.7508},{30,350,0.9211},{30,360,0.9803},{40,0,0.9361},{40,10,0.8794},{40,20,0.7163},{40,30,0.4664},{40,40,0.1598},{40,50,0.1598},{40,60,0.4664},{40,70,0.7163},{40,80,0.8794},{40,90,0.9361},{40,100,0.8794},{40,110,0.7163},{40,120,0.4664},{40,130,0.1598},{40,140,0.1598},{40,150,0.4664},{40,160,0.7163},{40,170,0.8794},{40,180,0.9361},{40,190,0.8794},{40,200,0.7163},{40,210,0.4664},{40,220,0.1598},{40,230,0.1598},{40,240,0.4664},{40,250,0.7163},{40,260,0.8794},{40,270,0.9361},{40,280,0.8794},{40,290,0.7163},{40,300,0.4664},{40,310,0.1598},{40,320,0.1598},{40,330,0.4664},{40,340,0.7163},{40,350,0.8794},{40,360,0.9361},{50,0,0.8418},{50,10,0.7903},{50,20,0.6421},{50,30,0.4149},{50,40,0.1361},{50,50,0.1361},{50,60,0.4149},{50,70,0.6421},{50,80,0.7903},{50,90,0.8418},{50,100,0.7903},{50,110,0.6421},{50,120,0.4149},{50,130,0.1361},{50,140,0.1361},{50,150,0.4149},{50,160,0.6421},{50,170,0.7903},{50,180,0.8418},{50,190,0.7903},{50,200,0.6421},{50,210,0.4149},{50,220,0.1361},{50,230,0.1361},{50,240,0.4149},{50,250,0.6421},{50,260,0.7903},{50,270,0.8418},{50,280,0.7903},{50,290,0.6421},{50,300,0.4149},{50,310,0.1361},{50,320,0.1361},{50,330,0.4149},{50,340,0.6421},{50,350,0.7903},{50,360,0.8418},{60,0,0.6765},{60,10,0.6337},{60,20,0.5106},{60,30,0.3219},{60,40,0.09022},{60,50,0.09022},{60,60,0.3219},{60,70,0.5106},{60,80,0.6337},{60,90,0.6765},{60,100,0.6337},{60,110,0.5106},{60,120,0.3219},{60,130,0.09022},{60,140,0.09022},{60,150,0.3219},{60,160,0.5106},{60,170,0.6337},{60,180,0.6765},{60,190,0.6337},{60,200,0.5106},{60,210,0.3219},{60,220,0.09022},{60,230,0.09022},{60,240,0.3219},{60,250,0.5106},{60,260,0.6337},{60,270,0.6765},{60,280,0.6337},{60,290,0.5106},{60,300,0.3219},{60,310,0.09022},{60,320,0.09022},{60,330,0.3219},{60,340,0.5106},{60,350,0.6337},{60,360,0.6765},{70,0,0.4340},{70,10,0.4037},{70,20,0.3162},{70,30,0.1820},{70,40,0.01681},{70,50,0.01681},{70,60,0.1820},{70,70,0.3162},{70,80,0.4037},{70,90,0.4340},{70,100,0.4037},{70,110,0.3162},{70,120,0.1820},{70,130,0.01681},{70,140,0.01681},{70,150,0.1820},{70,160,0.3162},{70,170,0.4037},{70,180,0.4340},{70,190,0.4037},{70,200,0.3162},{70,210,0.1820},{70,220,0.01681},{70,230,0.01681},{70,240,0.1820},{70,250,0.3162},{70,260,0.4037},{70,270,0.4340},{70,280,0.4037},{70,290,0.3162},{70,300,0.1820},{70,310,0.01681},{70,320,0.01681},{70,330,0.1820},{70,340,0.3162},{70,350,0.4037},{70,360,0.4340},{80,0,0.1373},{80,10,0.1218},{80,20,0.07700},{80,30,0.008029},{80,40,0},{80,50,0},{80,60,0.008029},{80,70,0.07700},{80,80,0.1218},{80,90,0.1373},{80,100,0.1218},{80,110,0.07700},{80,120,0.008029},{80,130,0},{80,140,0},{80,150,0.008029},{80,160,0.07700},{80,170,0.1218},{80,180,0.1373},{80,190,0.1218},{80,200,0.07700},{80,210,0.008029},{80,220,0},{80,230,0},{80,240,0.008029},{80,250,0.07700},{80,260,0.1218},{80,270,0.1373},{80,280,0.1218},{80,290,0.07700},{80,300,0.008029},{80,310,0},{80,320,0},{80,330,0.008029},{80,340,0.07700},{80,350,0.1218},{80,360,0.1373},{90,0,0},{90,10,0},{90,20,0},{90,30,0},{90,40,0},{90,50,0},{90,60,0},{90,70,0},{90,80,0},{90,90,0},{90,100,0},{90,110,0},{90,120,0},{90,130,0},{90,140,0},{90,150,0},{90,160,0},{90,170,0},{90,180,0},{90,190,0},{90,200,0},{90,210,0},{90,220,0},{90,230,0},{90,240,0},{90,250,0},{90,260,0},{90,270,0},{90,280,0},{90,290,0},{90,300,0},{90,310,0},{90,320,0},{90,330,0},{90,340,0},{90,350,0},{90,360,0},{100,0,0.05137},{100,10,0.03793},{100,20,0},{100,30,0},{100,40,0},{100,50,0},{100,60,0},{100,70,0},{100,80,0.03793},{100,90,0.05137},{100,100,0.03793},{100,110,0},{100,120,0},{100,130,0},{100,140,0},{100,150,0},{100,160,0},{100,170,0.03793},{100,180,0.05137},{100,190,0.03793},{100,200,0},{100,210,0},{100,220,0},{100,230,0},{100,240,0},{100,250,0},{100,260,0.03793},{100,270,0.05137},{100,280,0.03793},{100,290,0},{100,300,0},{100,310,0},{100,320,0},{100,330,0},{100,340,0},{100,350,0.03793},{100,360,0.05137},{110,0,0.2286},{110,10,0.2059},{110,20,0.1404},{110,30,0.03968},{110,40,0},{110,50,0},{110,60,0.03968},{110,70,0.1404},{110,80,0.2059},{110,90,0.2286},{110,100,0.2059},{110,110,0.1404},{110,120,0.03968},{110,130,0},{110,140,0},{110,150,0.03968},{110,160,0.1404},{110,170,0.2059},{110,180,0.2286},{110,190,0.2059},{110,200,0.1404},{110,210,0.03968},{110,220,0},{110,230,0},{110,240,0.03968},{110,250,0.1404},{110,260,0.2059},{110,270,0.2286},{110,280,0.2059},{110,290,0.1404},{110,300,0.03968},{110,310,0},{110,320,0},{110,330,0.03968},{110,340,0.1404},{110,350,0.2059},{110,360,0.2286},{120,0,0.3605},{120,10,0.3319},{120,20,0.2495},{120,30,0.1230},{120,40,0},{120,50,0},{120,60,0.1230},{120,70,0.2495},{120,80,0.3319},{120,90,0.3605},{120,100,0.3319},{120,110,0.2495},{120,120,0.1230},{120,130,0},{120,140,0},{120,150,0.1230},{120,160,0.2495},{120,170,0.3319},{120,180,0.3605},{120,190,0.3319},{120,200,0.2495},{120,210,0.1230},{120,220,0},{120,230,0},{120,240,0.1230},{120,250,0.2495},{120,260,0.3319},{120,270,0.3605},{120,280,0.3319},{120,290,0.2495},{120,300,0.1230},{120,310,0},{120,320,0},{120,330,0.1230},{120,340,0.2495},{120,350,0.3319},{120,360,0.3605},{130,0,0.4532},{130,10,0.4210},{130,20,0.3285},{130,30,0.1865},{130,40,0.01221},{130,50,0.01221},{130,60,0.1865},{130,70,0.3285},{130,80,0.4210},{130,90,0.4532},{130,100,0.4210},{130,110,0.3285},{130,120,0.1865},{130,130,0.01221},{130,140,0.01221},{130,150,0.1865},{130,160,0.3285},{130,170,0.4210},{130,180,0.4532},{130,190,0.4210},{130,200,0.3285},{130,210,0.1865},{130,220,0.01221},{130,230,0.01221},{130,240,0.1865},{130,250,0.3285},{130,260,0.4210},{130,270,0.4532},{130,280,0.4210},{130,290,0.3285},{130,300,0.1865},{130,310,0.01221},{130,320,0.01221},{130,330,0.1865},{130,340,0.3285},{130,350,0.4210},{130,360,0.4532},{140,0,0.5158},{140,10,0.4817},{140,20,0.3833},{140,30,0.2325},{140,40,0.04752},{140,50,0.04752},{140,60,0.2325},{140,70,0.3833},{140,80,0.4817},{140,90,0.5158},{140,100,0.4817},{140,110,0.3833},{140,120,0.2325},{140,130,0.04752},{140,140,0.04752},{140,150,0.2325},{140,160,0.3833},{140,170,0.4817},{140,180,0.5158},{140,190,0.4817},{140,200,0.3833},{140,210,0.2325},{140,220,0.04752},{140,230,0.04752},{140,240,0.2325},{140,250,0.3833},{140,260,0.4817},{140,270,0.5158},{140,280,0.4817},{140,290,0.3833},{140,300,0.2325},{140,310,0.04752},{140,320,0.04752},{140,330,0.2325},{140,340,0.3833},{140,350,0.4817},{140,360,0.5158},{150,0,0.5567},{150,10,0.5215},{150,20,0.4199},{150,30,0.2643},{150,40,0.07340},{150,50,0.07340},{150,60,0.2643},{150,70,0.4199},{150,80,0.5215},{150,90,0.5567},{150,100,0.5215},{150,110,0.4199},{150,120,0.2643},{150,130,0.07340},{150,140,0.07340},{150,150,0.2643},{150,160,0.4199},{150,170,0.5215},{150,180,0.5567},{150,190,0.5215},{150,200,0.4199},{150,210,0.2643},{150,220,0.07340},{150,230,0.07340},{150,240,0.2643},{150,250,0.4199},{150,260,0.5215},{150,270,0.5567},{150,280,0.5215},{150,290,0.4199},{150,300,0.2643},{150,310,0.07340},{150,320,0.07340},{150,330,0.2643},{150,340,0.4199},{150,350,0.5215},{150,360,0.5567},{160,0,0.5820},{160,10,0.5462},{160,20,0.4429},{160,30,0.2848},{160,40,0.09086},{160,50,0.09086},{160,60,0.2848},{160,70,0.4429},{160,80,0.5462},{160,90,0.5820},{160,100,0.5462},{160,110,0.4429},{160,120,0.2848},{160,130,0.09086},{160,140,0.09086},{160,150,0.2848},{160,160,0.4429},{160,170,0.5462},{160,180,0.5820},{160,190,0.5462},{160,200,0.4429},{160,210,0.2848},{160,220,0.09086},{160,230,0.09086},{160,240,0.2848},{160,250,0.4429},{160,260,0.5462},{160,270,0.5820},{160,280,0.5462},{160,290,0.4429},{160,300,0.2848},{160,310,0.09086},{160,320,0.09086},{160,330,0.2848},{160,340,0.4429},{160,350,0.5462},{160,360,0.5820},{170,0,0.5957},{170,10,0.5596},{170,20,0.4556},{170,30,0.2963},{170,40,0.1009},{170,50,0.1009},{170,60,0.2963},{170,70,0.4556},{170,80,0.5596},{170,90,0.5957},{170,100,0.5596},{170,110,0.4556},{170,120,0.2963},{170,130,0.1009},{170,140,0.1009},{170,150,0.2963},{170,160,0.4556},{170,170,0.5596},{170,180,0.5957},{170,190,0.5596},{170,200,0.4556},{170,210,0.2963},{170,220,0.1009},{170,230,0.1009},{170,240,0.2963},{170,250,0.4556},{170,260,0.5596},{170,270,0.5957},{170,280,0.5596},{170,290,0.4556},{170,300,0.2963},{170,310,0.1009},{170,320,0.1009},{170,330,0.2963},{170,340,0.4556},{170,350,0.5596},{170,360,0.5957},{180,0,0.6000},{180,10,0.5638},{180,20,0.4596},{180,30,0.3000},{180,40,0.1042},{180,50,0.1042},{180,60,0.3000},{180,70,0.4596},{180,80,0.5638},{180,90,0.6000},{180,100,0.5638},{180,110,0.4596},{180,120,0.3000},{180,130,0.1042},{180,140,0.1042},{180,150,0.3000},{180,160,0.4596},{180,170,0.5638},{180,180,0.6000},{180,190,0.5638},{180,200,0.4596},{180,210,0.3000},{180,220,0.1042},{180,230,0.1042},{180,240,0.3000},{180,250,0.4596},{180,260,0.5638},{180,270,0.6000},{180,280,0.5638},{180,290,0.4596},{180,300,0.3000},{180,310,0.1042},{180,320,0.1042},{180,330,0.3000},{180,340,0.4596},{180,350,0.5638},{180,360,0.6000}};

Using this data one defines the function interpfdata, where

interpfdata = 
  Interpolation[{{#[[1]] Degree, #[[2]] Degree}, #[[3]]} & /@ 
    data];

Now define a set of axis and a small sphere situated at the origin of this coordinate system and plot these together with interpfdata using SphericalPlot3D. The code for doing all this looks like

(*Define the Cartesian coordinate axes as tubular cylinders*)
axisDiameter = 0.01;
axes = Graphics3D[{
    {Red, Opacity[0.8], 
     Arrow@Tube[{{0, 0, 0}, {-1.5, 0, 0}}, axisDiameter]}, {Red, 
     Opacity[0.8], Arrow@Tube[{{0, 0, 0}, {1.5, 0, 0}}, axisDiameter]},
    {Green, Opacity[0.8], 
     Arrow@Tube[{{0, 0, 0}, {0, -1.5, 0}}, axisDiameter]}, {Green, 
     Opacity[0.8], Arrow@Tube[{{0, 0, 0}, {0, 1.5, 0}}, axisDiameter]},
    {Yellow, Opacity[0.8], 
     Arrow@Tube[{{0, 0, 0}, {0, 0, -1.5}}, axisDiameter]}, {Yellow, 
     Opacity[0.8], Arrow@Tube[{{0, 0, 0}, {0, 0, 1.5}}, axisDiameter]},
    {White, Opacity[1], Sphere[{0, 0, 0}, 0.1]}
    }];

(*Plot interpfdata together with the Cartesian coordinate axes and small sphere*)
gn = Show[SphericalPlot3D[1, {\[Theta], 0, \[Pi]}, {\[Phi], 0, 2 \[Pi]}, 
  ColorFunction -> (ColorData["SunsetColors", "ColorFunction"][
      interpfdata[#4, #5]] &), Mesh -> 9, 
  MeshFunctions -> {interpfdata[#4, #5] &}, 
  ColorFunctionScaling -> False, Boxed -> False, 
  PlotRangePadding -> {0.8, 0.8, 0.8}, Axes -> False, 
  PlotPoints -> 50, PlotLegends -> "Expressions", 
  PlotStyle -> Directive[Opacity[0.6], Specularity[White, 10]], 
  MeshStyle -> {Cyan, Directive[Blue, Dashed]}, ImageSize -> 600, 
  ViewAngle -> 0.5007002891092921`, 
  ViewPoint -> {-0.8717626022744285`, -2.0403527414826437`, 
    2.5547975762474744`}, 
  ViewVertical -> {-0.9317453834809479`, -0.21632043441240897`, 
    0.29164363531126125`}], axes]

If you run this code, you should see something like this:

enter image description here

What I would like to do now is import this into Solidworks. The background colour can be invisible but I would like to retain all of the colours of the object.

I did attempt this following suggestion;

gn = Normal[gn /. GeometricTransformation[prims_, tf_List] :>
    (GeometricTransformation[prims, #] & /@ tf)]

Export["test.stl", gn]

where gn is defined as (see large code above)

gn = Show[SphericalPlot3D[1, {\[Theta], 0, \[Pi]}, {\[Phi], 0, 2 \[Pi]}, 
  ColorFunction -> (ColorData["SunsetColors", "ColorFunction"][
      interpfdata[#4, #5]] &), Mesh -> 9, 
  MeshFunctions -> {interpfdata[#4, #5] &}, 
  ColorFunctionScaling -> False, Boxed -> False, 
  PlotRangePadding -> {0.8, 0.8, 0.8}, Axes -> False, 
  PlotPoints -> 50, PlotLegends -> "Expressions", 
  PlotStyle -> Directive[Opacity[0.6], Specularity[White, 10]], 
  MeshStyle -> {Cyan, Directive[Blue, Dashed]}, ImageSize -> 600, 
  ViewAngle -> 0.5007002891092921`, 
  ViewPoint -> {-0.8717626022744285`, -2.0403527414826437`, 
    2.5547975762474744`}, 
  ViewVertical -> {-0.9317453834809479`, -0.21632043441240897`, 
    0.29164363531126125`}], axes]

This surprisingly did generate a stl extension file without any errors, even though this solution was for Graphics3D objects.

If you try opening this test.stl file in SolidWorks the first thing you see is this warning message:

enter image description here

If you press OK, you should see the following image:

enter image description here

I adjusted the transparency of the outer shell to make the small sphere visible. As you can see, most of the objects were successfully imported, with the exception of the arrowheads. Unfortunately, I lost the color scheme on the outer sphere as you can see when one compares the Mathematica plot side by side with the test.stl.

enter image description here

Importantly, this is the part I want to bring into Solidworks. The axis, arrowheads, and the small sphere are not a problem if they are not imported. It's the outer shell with all its features, as shown in the Mathematica plot, that I would like to see in Solidworks.

We do have the flexibility of choosing other extensions. Here is a dropdown menue of possible file extensions one can choose:

enter image description here

I have no idea how to proceed next. If anyone can offer some idea I would much appreciate it.

Thanks for reaching all the way to here. :)

$\endgroup$
4
  • 1
    $\begingroup$ "This surprisingly did generate a stl extension file without any errors, even though this solution was for Graphics3D objects." …This isn't surprising. SphericalPlot3D and most (if not all) of those *Plot3D functions are just generators of Graphics3D[…]. $\endgroup$
    – xzczd
    Nov 16, 2023 at 2:06
  • $\begingroup$ Related: mathematica.stackexchange.com/a/178319/1871 $\endgroup$
    – xzczd
    Nov 16, 2023 at 2:10
  • 1
    $\begingroup$ Try to use Arrow@Tube[...] instead of Cylinder and plain Arrow to plot axes. $\endgroup$ Nov 16, 2023 at 21:21
  • $\begingroup$ Hi @azerbajdzan! Thanks for that suggestion! That was exactly what I was trying to do with the arrow heads. I've updated the code and the output image looks like now in Mathematica. I can't yet update the comparison images (Mathematica and stl image) because I'm in the middle of trying some things. Will do so later. Thanks again. $\endgroup$ Nov 16, 2023 at 23:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.