3
$\begingroup$

There is a code for a revolution of Koch Snowflake I just want to export it as an obj file (or any other 3D format)

kochinsert[pts_?MatrixQ] := 
Insert[#, 
Composition[TranslationTransform[#[[2]] - #[[1]]], 
  RotationTransform[-\[Pi]/3, #[[1]]]][#[[2]]], 3] &[
Transpose[{1 - #, #}] &[Subdivide[3]].pts]

koch[pts_?MatrixQ] := 
Apply[Join, Prepend[Rest /@ Rest[#], First[#]]] &[
kochinsert /@ Partition[pts, 2, 1]]

halfkoch = {{0, 1}, {-1/(2 Sqrt[3]), 1/2}, {-Sqrt[3]/2, 
1/2}, {-Sqrt[3]/2, 1/2}, {-1/Sqrt[3], 
0}, {-Sqrt[3]/2, -1/2}, {-1/(2 Sqrt[3]), -1/2}, {0, -1}};

snowflake = Nest[koch, N[halfkoch, 20], 4];

circPoints = {{1, 0}, {1, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {1, -1}, {1,0}};
circKnots = {0, 0, 0, 1/4, 1/2, 1/2, 3/4, 1, 1, 1};
circWts = {1, 1/2, 1/2, 1, 1/2, 1/2, 1};

graphics = 
Graphics3D[BSplineSurface[
Map[Function[pt, Append[#1 pt, #2]], circPoints] & @@@ snowflake, 
SplineClosed -> True, SplineDegree -> {1, 2}, 
SplineKnots -> {Automatic, circKnots}, 
SplineWeights -> ConstantArray[circWts, Length[snowflake]]],Boxed -> False]

I simply tried to export it as an obj file, but the given file is a very low resolution.

Export["KochSnowflakeRe.obj", graphics]

before

enter image description here

after

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ I think maybe other format doesn't support NURBS surfaces. $\endgroup$
    – cvgmt
    Nov 25, 2020 at 14:29

1 Answer 1

8
$\begingroup$

If you use the code in my answer and convert the result to a MeshRegion using DiscretizeGraphics, then the result exports to OBJ at a reasonable resolution. Here's what it looks like on 3dviewer.net:

enter image description here

You can also see an rotatable and colored version (after conversion to X3D) in this Observable notebook. I added the color by manually editing the X3D file.

A couple of comments:

  • Mathematica's export to external 3D formats is generally a bit weak. It makes a bit of sense, though, that we should be able to export MeshRegions a bit easier, since the object is triangulated
  • While the answer you referred to looks nice in Mathematica, I'm not surprised it doesn't export well. Splines are meant to approximate smooth objects so it doesn't make much sense to represent a fractal object using splines.
  • In principle, you should be able to generate a rotatable version of any Graphics3D object using CloudDeploy. That doesn't seem to work too well for these complicated graphics but, again, it works OK for the triangulated MeshRegion version.
$\endgroup$
1
  • $\begingroup$ Mark, I can’t seem to access the cloud deploy you’ve linked to. $\endgroup$ Dec 5, 2020 at 21:02

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.