Wrapping text around a complex geometry

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Wrapping text around a complex geometry

alexgibson
Hi all

I am designing a pair of earrings based on a Mobius band, with text
subtracted from its flat surface.

One example of an OpenSCAD script to generate a Mobius band is here:
http://kitwallace.tumblr.com/post/75264490978/mobius-strip

I'm struggling slightly to wrap text around this geometry.  The best I
can come up with so far is to subtract the text from a simple cuboid,
then chop it into many slices and twist them from -90 to +90 degrees
along the length, then bend the whole thing around a circle (or even
ellipse).  

Has anyone a neat trick to do this in an efficient manner which can
generate a nice high resolution output?

The result will be printed by Shapeways at high resolution in stainless
steel and polished, for an 11th wedding anniversary present...

Cheers
Alex

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Wrapping text around a complex geometry

Ronaldo
The usual technique is to chop the text in small pieces and to position them accordingly over the target surface. As the Moebius strip is a ruled surface and the model you referred is made of slightly twisted and tapered thin blocks, I used them to chop the text.


Moebius_strip_text.scad

The above image has been rendered in 4 min with a step size of 5 degrees. A finer 1 degree model required 32 min to render.

Hope it helps.
Reply | Threaded
Open this post in threaded view
|

Re: Wrapping text around a complex geometry

frankv

I recently did an OpenSCAD program to wrap an image around a conic surface, and also to do it for any surface which can be defined by Z=f (X,Y). If you render your text to a PNG file, you might be able to apply this? But I don't know enough maths to know whether that would work for a complex geometry like a moebius strip (I suspect not).  Thingiverse 1668883


On 18/08/2016 17:38, "Ronaldo" <[hidden email]> wrote:
The usual technique is to chop the text in small pieces and to position them
accordingly over the target surface. As the Moebius strip is a ruled surface
and the model you referred is made of slightly twisted and tapered thin
blocks, I used them to chop the text.
<http://forum.openscad.org/file/n18156/Moebius_text.png>

Moebius_strip_text.scad
<http://forum.openscad.org/file/n18156/Moebius_strip_text.scad>

The above image has been rendered in 4 min with a step size of 5 degrees. A
finer 1 degree model required 32 min to render.

Hope it helps.



--
View this message in context: http://forum.openscad.org/Wrapping-text-around-a-complex-geometry-tp18145p18156.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Wrapping text around a complex geometry

alexgibson
In reply to this post by Ronaldo
Thanks, this is the method I had in mind but it's great to confirm and you've given me a great leg up!

Cheers
Alex

Tapped on my mobile phone.

> On 18 Aug 2016, at 07:37, Ronaldo <[hidden email]> wrote:
>
> The usual technique is to chop the text in small pieces and to position them
> accordingly over the target surface. As the Moebius strip is a ruled surface
> and the model you referred is made of slightly twisted and tapered thin
> blocks, I used them to chop the text.
> <http://forum.openscad.org/file/n18156/Moebius_text.png>
>
> Moebius_strip_text.scad
> <http://forum.openscad.org/file/n18156/Moebius_strip_text.scad>  
>
> The above image has been rendered in 4 min with a step size of 5 degrees. A
> finer 1 degree model required 32 min to render.
>
> Hope it helps.
>
>
>
> --
> View this message in context: http://forum.openscad.org/Wrapping-text-around-a-complex-geometry-tp18145p18156.html
> Sent from the OpenSCAD mailing list archive at Nabble.com.
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Wrapping text around a complex geometry

Trygon
Another way of approaching this type of problem is set out below. I have used this in the past and IMO it is theoretically more elegant, however its implementation in OpenSCAD is far less so...

Taking a simple example of a cube:
  cube(10);

Render and export as an Additive Manufacturing File (AMF).

Load the AMF file into a text editor and reformat the xml vertex and triangle data into a OpenSCAD script format. This is most easily done using a find & replace macro, an example of a VB macro for Word is included at the end (this is definitely not elegant but got the job done :) ).

Paste the result into OpenSCAD:

points=[[0,0,10],[0,10,10],[0,0,0],[0,10,0],[10,0,10],[10,10,10],[10,0,0],[10,10,0]];
triangles=[[0,1,2],[2,1,3],[0,4,5],[1,0,5],[2,6,4],[0,2,4],[3,7,2],[2,7,6],[1,5,3],[3,5,7],[6,7,5],[4,6,5]];
polyhedron(points,triangles);

It produces the same cube, but you now have access to the raw vertex data.

Now using text as an example:
  linear_extrude(height=1) text("Hello world!");

Again render and export as an AMF file. Then load and reformat the AMF file in a text editor, before pasting back into the OpenSCAD editor:

points=[[64.7295,0.582993,0],[64.9412,0.860992,0],...[46.3348,3.687,1]];
triangles=[[0,1,2],[3,0,2],...[632,633,693]];
polyhedron(points,triangles);

This produces the same text object.

However the vertex data can be re-mapped (non-affine transformation), for example:
  points2=[ for(i=points) [i[0],i[1]+5*sin(8*i[0]),4*i[2]] ];
  polyhedron(points2,triangles);



Using a suitable mapping the text can be wrapped around a surface:

r1=20;
points3=[ for(i=points) let(a=1.7*i[0],r=r1+2*i[2]-1) [-r*cos(a),i[1],r*sin(a)] ];
difference(){
    rotate([90,0,0]) cylinder(r=r1,h=25,center=true,$fn=60);
    polyhedron(points3,triangles,convexity=10);
}




Cheers,
Trygon

---------------
' VB Microsoft Word macro

Sub AMFtoOpenSCAD()

    Dim CRLF As String
    CRLF = Chr(13) + Chr(10)

    ReplaceText " ", ""
   
    ReplaceText "<mesh>", CRLF
    ReplaceText "</mesh>", CRLF + "polyhedron(points,triangles);" + CRLF
   
    ReplaceText "<vertices>", CRLF + "points=["
    ReplaceText "</vertices>", "];" + CRLF
    ReplaceText "</vertex><vertex>", ","
    ReplaceText "<vertex>", ""
    ReplaceText "</vertex>", ""
    ReplaceText "<coordinates>", "["
    ReplaceText "</coordinates>", "]"
    ReplaceText "<x>", ""
    ReplaceText "</x>", ","
    ReplaceText "<y>", ""
    ReplaceText "</y>", ","
    ReplaceText "<z>", ""
    ReplaceText "</z>", ""
   
    ReplaceText "<volume>", CRLF + "triangles=["
    ReplaceText "</volume>", "];" + CRLF
    ReplaceText "</triangle><triangle>", "],["
    ReplaceText "<triangle>", "["
    ReplaceText "</triangle>", "]"
    ReplaceText "<v1>", ""
    ReplaceText "</v1>", ","
    ReplaceText "<v2>", ""
    ReplaceText "</v2>", ","
    ReplaceText "<v3>", ""
    ReplaceText "</v3>", ""

End Sub

Sub ReplaceText(text1 As String, text2 As String)
    With Selection.Find
        .Text = text1
        .Replacement.Text = text2
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub

-ends-
Reply | Threaded
Open this post in threaded view
|

Re: Wrapping text around a complex geometry

Ronaldo
Trygon,
I've trying such technique but with a different combination: STL - Notepad++ using macros with regular expression finds. It is a very general technique but it is far from elegant. Elegant would be to have a function or module in OpenSCAD to retrieve the polyhedron data of any solid. Something like:

data = polyhedron_data() cube();

where data would be of the form: [ <vertex list>, <facet list> ].

This would require that modules returned values (as functions do) or functions accepted solids as parameters (as module do in some sense).

May be in OpenSCAD2...

2016-08-18 18:26 GMT-03:00 Trygon <[hidden email]>:
Another way of approaching this type of problem is set out below. I have used
this in the past and IMO it is theoretically more elegant, however its
implementation in OpenSCAD is far less so...

Taking a simple example of a cube:
  cube(10);

Render and export as an Additive Manufacturing File (AMF).

Load the AMF file into a text editor and reformat the xml vertex and
triangle data into a OpenSCAD script format. This is most easily done using
a find & replace macro, an example of a VB macro for Word is included at the
end (this is definitely not elegant but got the job done :) ).

Paste the result into OpenSCAD:

points=[[0,0,10],[0,10,10],[0,0,0],[0,10,0],[10,0,10],[10,10,10],[10,0,0],[10,10,0]];
triangles=[[0,1,2],[2,1,3],[0,4,5],[1,0,5],[2,6,4],[0,2,4],[3,7,2],[2,7,6],[1,5,3],[3,5,7],[6,7,5],[4,6,5]];
polyhedron(points,triangles);

It produces the same cube, but you now have access to the raw vertex data.

Now using text as an example:
  linear_extrude(height=1) text("Hello world!");

Again render and export as an AMF file. Then load and reformat the AMF file
in a text editor, before pasting back into the OpenSCAD editor:

points=[[64.7295,0.582993,0],[64.9412,0.860992,0],...[46.3348,3.687,1]];
triangles=[[0,1,2],[3,0,2],...[632,633,693]];
polyhedron(points,triangles);

This produces the same text object.

However the vertex data can be re-mapped (non-affine transformation), for
example:
  points2=[ for(i=points) [i[0],i[1]+5*sin(8*i[0]),4*i[2]] ];
  polyhedron(points2,triangles);

<http://forum.openscad.org/file/n18163/HelloWorld2.png>

Using a suitable mapping the text can be wrapped around a surface:

r1=20;
points3=[ for(i=points) let(a=1.7*i[0],r=r1+2*i[2]-1)
[-r*cos(a),i[1],r*sin(a)] ];
difference(){
    rotate([90,0,0]) cylinder(r=r1,h=25,center=true,$fn=60);
    polyhedron(points3,triangles,convexity=10);
}

<http://forum.openscad.org/file/n18163/HelloWorld3.png>


Cheers,
Trygon

---------------
' VB Microsoft Word macro

Sub AMFtoOpenSCAD()

    Dim CRLF As String
    CRLF = Chr(13) + Chr(10)

    ReplaceText " ", ""

    ReplaceText "<mesh>", CRLF
    ReplaceText "</mesh>", CRLF + "polyhedron(points,triangles);" + CRLF

    ReplaceText "<vertices>", CRLF + "points=["
    ReplaceText "</vertices>", "];" + CRLF
    ReplaceText "</vertex><vertex>", ","
    ReplaceText "<vertex>", ""
    ReplaceText "</vertex>", ""
    ReplaceText "<coordinates>", "["
    ReplaceText "</coordinates>", "]"
    ReplaceText "<x>", ""
    ReplaceText "</x>", ","
    ReplaceText "<y>", ""
    ReplaceText "</y>", ","
    ReplaceText "<z>", ""
    ReplaceText "</z>", ""

    ReplaceText "<volume>", CRLF + "triangles=["
    ReplaceText "</volume>", "];" + CRLF
    ReplaceText "</triangle><triangle>", "],["
    ReplaceText "<triangle>", "["
    ReplaceText "</triangle>", "]"
    ReplaceText "<v1>", ""
    ReplaceText "</v1>", ","
    ReplaceText "<v2>", ""
    ReplaceText "</v2>", ","
    ReplaceText "<v3>", ""
    ReplaceText "</v3>", ""

End Sub

Sub ReplaceText(text1 As String, text2 As String)
    With Selection.Find
        .Text = text1
        .Replacement.Text = text2
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub

-ends-




--
View this message in context: http://forum.openscad.org/Wrapping-text-around-a-complex-geometry-tp18145p18163.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Wrapping text around a complex geometry

Neon22
I've added a python program to convert AMF files into polyhedron scad format files.
Check it out here:
- https://github.com/Neon22/amf-to-openscad-polyhedron

Any testing would be great. I've tried to make it so you can just drop an AMF file onto the python program but that will only work if you have it setup in your OS (Win or Mac) correctly - don't ask me how.

For everyone else, the first couple of lines has the filename of the AMF file like so:
# manual file defined
filename = "test.amf"

just edit that and run it.
Reply | Threaded
Open this post in threaded view
|

Re: Wrapping text around a complex geometry

drxenocide
In reply to this post by Trygon
You people are great, these discussions always leave me feeling very stupid, but smiling. Hopefully the algorithms you are hashing out can be imported to standard OpenSCAD someday. I too would like to map text to something other than a flat surface. But now I realize that it wasn't my tensor math that wasn't good enough, but my coding as well.

Well done, all.

On Sat, Aug 20, 2016 at 12:53 PM, Ronaldo Persiano <[hidden email]> wrote:
Nice solution. I would expect a refined discretization of the imported polyhedron before the transformations.

2016-08-20 10:55 GMT-03:00 Trygon <[hidden email]>:
Hi Alex,

Some more ideas for you...

1) Make a flat strip with the required writing engraved into both sides:

/l=170; w=10; d=2; // strip size
s=6; // text size

difference(){
    translate([l/2,0,0]) cube([l,w,d],center=true);
    translate([0,0,0.5]) linear_extrude(height=1)
        text("If music be the food of love, play on.  So full
of",size=s,valign="center");
    rotate([180,0,0]) translate([0,0,0.5]) linear_extrude(height=1)
        text("shapes is fancy that it alone is high
fantastical.",size=s,valign="center");
}
/

<http://forum.openscad.org/file/n18183/FlatStrip1.png>

<http://forum.openscad.org/file/n18183/FlatStrip2.png>

Export and reimport as an OpenSCAD script - see Neon22's excellent Python
script above.

Using a non-affine transformation twist the strip 180 degrees along its axis
(i.e. along the x-axis):

<http://forum.openscad.org/file/n18183/TwistedStrip.png>

Then using a second non-affine transformation roll the twisted strip around
a circle on the x-z plane centred on the origin:

<http://forum.openscad.org/file/n18183/MobiusBand.png>

The script I used for both transformations combined is:

/include<FlatStrip_convert.scad>;

l=170; w=10; d=2; // strip size
eps=0.001;
l2=l+2*eps; // +2*eps => avoid self intersecting polyhedron
r1=l2/(2*PI);

points2=[ for(i=points) let( a1=360*(i[0]+eps)/l2,
                             a2=a1/2,
                             rm1=[cos(a1),-sin(a1)],
                             rm2=[[cos(a2),-sin(a2)],[sin(a2),cos(a2)]],
                             p1=[i[1],i[2]]*rm2+[0,r1],
                             p2=p1[1]*rm1 )
          [p2[0],p1[0],p2[1]] ];

union(){
    polyhedron(points2,triangles,convexity=10);
    translate([r1,0,0]) cube([d,w,4*eps],center=true); // join strip
}
/

This method is the same way you could go about making a mobius band out of a
strip of paper.

Cheers,
Trygon




--
View this message in context: http://forum.openscad.org/Wrapping-text-around-a-complex-geometry-tp18145p18183.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org