Skip to content

Instantly share code, notes, and snippets.

# arnholm/melting.md Last active May 25, 2019

Step one, download "gregs-large.stl" from https://www.thingiverse.com/thing:6713/files and convert it into OBJ format and read it into AngelCAD, and "melt" it

AngelCAD language reference https://arnholm.github.io/angelcad-docs/docs/annotated.html

```// AngelCAD code.

shape@ main_shape()
{
auto@ p = polyhedron("gregs-large.obj");

// traverse the vertices
double factor = 0.025;
for(uint i=0; i<p.nvert(); i++) {

// get position of this vertex
pos3d@ vtx = p.vertex(i);
double t   = vtx.x();
if(t > 0.0) {

// transform vertex by rotation
double angle = factor*t*PI/4;
@vtx = rotate_y(rad:angle)*vtx;
p.set_vertex(i,vtx);
}
}

return p;
}

void main()
{
shape@ obj = main_shape();
obj.write_xcsg(GetInputFullPath(),secant_tolerance:-1.0);
}
```

This works in principle, but the result is ugly due to the coarse mesh: Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Step two, we remesh the file to have 4mm sized triangles so that "melting" will work better

``````\$ polyfix gregs-large.stl gregs-large_remesh.obj -remesh=4 -dtol=1E-6
``````

Then perform the same operation on the remeshed file.

```// AngelCAD code.

shape@ main_shape()
{
auto@ p = polyhedron("gregs-large_remesh.obj");

// traverse the vertices
double factor = 0.025;
for(uint i=0; i<p.nvert(); i++) {

// get position of this vertex
pos3d@ vtx = p.vertex(i);
double t   = vtx.x();
if(t > 0.0) {

// transform vertex by rotation
double angle = factor*t*PI/4;
@vtx = rotate_y(rad:angle)*vtx;
p.set_vertex(i,vtx);
}
}

return p;
}

void main()
{
shape@ obj = main_shape();
obj.write_xcsg(GetInputFullPath(),secant_tolerance:-1.0);
}
```

This time, the result is as we want: Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.