discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Engrave text in a curved surface?

DE
David Eccles (gringer)
Thu, Apr 15, 2021 10:15 AM

Depending on how precise you want it to be, you could get a similar effect by
doing a per-letter cut into the cylinder, then adding another cylinder on
the inside to tidy up the cuts. This would have parallel cuts rather than
radial cuts, and curves wouldn't quite match fully-mapped text:

====

rotate([0,0,-$t * 360]){
difference(){
cylinder(r=60, h=100, $fn=100, center=true);
for(ltl = [0, 1]){
lArr = ["ENGRAVED", "TEXT"][ltl];
cCirc = 2 * PI * 60;
for(lp = [0:(len(lArr)-1)]){
rotate((lp16)/cCirc * 360+(ltl * 28)) translate([60,0,-ltl20])
rotate([90,0,90])
linear_extrude(height=20, center=true){
text(lArr[lp], size=16, font = "Linux Biolinum");
}
}
}
}
color("green") cylinder(r=56, h=98, $fn=200, center=true);
}

====

http://forum.openscad.org/file/t452/text_engraved_cheating.png

--
Sent from: http://forum.openscad.org/

Depending on how precise you want it to be, you could get a similar effect by doing a per-letter cut into the cylinder, then adding another cylinder on the inside to tidy up the cuts. This would have parallel cuts rather than radial cuts, and curves wouldn't quite match fully-mapped text: ==== rotate([0,0,-$t * 360]){ difference(){ cylinder(r=60, h=100, $fn=100, center=true); for(ltl = [0, 1]){ lArr = ["ENGRAVED", "TEXT"][ltl]; cCirc = 2 * PI * 60; for(lp = [0:(len(lArr)-1)]){ rotate((lp*16)/cCirc * 360+(ltl * 28)) translate([60,0,-ltl*20]) rotate([90,0,90]) linear_extrude(height=20, center=true){ text(lArr[lp], size=16, font = "Linux Biolinum"); } } } } color("green") cylinder(r=56, h=98, $fn=200, center=true); } ==== <http://forum.openscad.org/file/t452/text_engraved_cheating.png> -- Sent from: http://forum.openscad.org/
AC
A. Craig West
Thu, Apr 15, 2021 12:52 PM

I found my problem, and cleaned it up a bit. I redid the math on the bend
module, it is now much more accurate

On Wed, Apr 14, 2021 at 6:02 PM A. Craig West acraigwest@gmail.com wrote:

I will note that I just noticed that the code doesn't work proper if $fn
is less than 8, I am still working out what I did wrong

On Wed, Apr 14, 2021 at 5:50 PM A. Craig West acraigwest@gmail.com
wrote:

A better version of it would be in the attached bend.scad. I had at least
one bit of code leftover from the project I stole it from, and it depended
on $fn being set, which is not always the case... the render() call
wrapping the actual call to labeledDisc helps a lot for the speed, although
it is still not blazingly fast by any means.

On Wed, Apr 14, 2021 at 4:55 PM Maurice van Peursem <
openscad@vanpeursem.net> wrote:

This looks very good, but could you please provide a working example
call? It is not completely clear to me how to use your code.

Cheers,
Maurice

I have code that does this, but it is VERY slow on any significant
amounts of text (The bend module is the key one, the rest of it sets
up what to bend):

module inscribe2d(depth, baseOffset, width = 0, height = 0) {
translate([0, 0, baseOffset - depth]) {
linear_extrude(depth, center = false) {
if (width > 0 || height > 0) {
resize([width, height], auto=[true, true, false]) {
children();
}
} else {
children();
}
}
}
}

module monogram(text, font, depth, baseOffset, width = 0, height = 0) {
inscribe2d(depth, baseOffset, width, height) {
if (is_undef(font)) {
text(text, size = 10, valign = "center", halign = "center");
} else {
text(text, font = font, size = 10, valign = "center", halign =
"center");
}
}
}

module bend(radius, angleOffset = 0) {
stepAngle = 360 / $fn;
stepWidth = 2 * PI * radius / $fn;
union() {
for (step = [-$fn : $fn]) {
angle = step * stepAngle + angleOffset;
offset = step * stepWidth;
translate([0, 0, radius]) {
rotate([0, -angle, 0]) {
translate([-offset, 0, -radius]) {
intersection() {
children();
translate([offset, 0, 0]) {
cube(size = [stepWidth, stepWidth * $fn, stepWidth *
$fn], center = true);
}
}
}
}
}
}
}
}

module labeledDisc(radius, thickness, label = undef) {
difference() {
rotate([0, 0, 180 / $fn]) {
cylinder(r = radius, h = thickness, center = true);
}
if (SHOW_TEXT && !is_undef(label)) {
rotate([90, 0, -90]) {
translate([0, 0, -radius]) {
bend(radius = radius, angleOffset = 90) {
scale([-1, 1, 1]) {
monogram(label, height = (thickness * 0.8), depth =
2.01, baseOffset = 2);
}
}
}
}
rotate([90, 180, -90]) {
translate([0, 0, -radius]) {
bend(radius = radius, angleOffset = 90) {
scale([-1, 1, 1]) {
monogram(label, height = (thickness * 0.8), depth =
2.01, baseOffset = 2);
}
}
}
}
}
}
}


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

I found my problem, and cleaned it up a bit. I redid the math on the bend module, it is now much more accurate On Wed, Apr 14, 2021 at 6:02 PM A. Craig West <acraigwest@gmail.com> wrote: > I will note that I just noticed that the code doesn't work proper if $fn > is less than 8, I am still working out what I did wrong > > On Wed, Apr 14, 2021 at 5:50 PM A. Craig West <acraigwest@gmail.com> > wrote: > >> A better version of it would be in the attached bend.scad. I had at least >> one bit of code leftover from the project I stole it from, and it depended >> on $fn being set, which is not always the case... the render() call >> wrapping the actual call to labeledDisc helps a lot for the speed, although >> it is still not blazingly fast by any means. >> >> On Wed, Apr 14, 2021 at 4:55 PM Maurice van Peursem < >> openscad@vanpeursem.net> wrote: >> >>> This looks very good, but could you please provide a working example >>> call? It is not completely clear to me how to use your code. >>> >>> Cheers, >>> Maurice >>> >>> >I have code that does this, but it is VERY slow on any significant >>> >amounts of text (The bend module is the key one, the rest of it sets >>> >up what to bend): >>> > >>> >module inscribe2d(depth, baseOffset, width = 0, height = 0) { >>> > translate([0, 0, baseOffset - depth]) { >>> > linear_extrude(depth, center = false) { >>> > if (width > 0 || height > 0) { >>> > resize([width, height], auto=[true, true, false]) { >>> > children(); >>> > } >>> > } else { >>> > children(); >>> > } >>> > } >>> > } >>> >} >>> > >>> > >>> >module monogram(text, font, depth, baseOffset, width = 0, height = 0) { >>> > inscribe2d(depth, baseOffset, width, height) { >>> > if (is_undef(font)) { >>> > text(text, size = 10, valign = "center", halign = "center"); >>> > } else { >>> > text(text, font = font, size = 10, valign = "center", halign = >>> >"center"); >>> > } >>> > } >>> >} >>> > >>> > >>> >module bend(radius, angleOffset = 0) { >>> > stepAngle = 360 / $fn; >>> > stepWidth = 2 * PI * radius / $fn; >>> > union() { >>> > for (step = [-$fn : $fn]) { >>> > angle = step * stepAngle + angleOffset; >>> > offset = step * stepWidth; >>> > translate([0, 0, radius]) { >>> > rotate([0, -angle, 0]) { >>> > translate([-offset, 0, -radius]) { >>> > intersection() { >>> > children(); >>> > translate([offset, 0, 0]) { >>> > cube(size = [stepWidth, stepWidth * $fn, stepWidth * >>> >$fn], center = true); >>> > } >>> > } >>> > } >>> > } >>> > } >>> > } >>> > } >>> >} >>> > >>> >module labeledDisc(radius, thickness, label = undef) { >>> > difference() { >>> > rotate([0, 0, 180 / $fn]) { >>> > cylinder(r = radius, h = thickness, center = true); >>> > } >>> > if (SHOW_TEXT && !is_undef(label)) { >>> > rotate([90, 0, -90]) { >>> > translate([0, 0, -radius]) { >>> > bend(radius = radius, angleOffset = 90) { >>> > scale([-1, 1, 1]) { >>> > monogram(label, height = (thickness * 0.8), depth = >>> >2.01, baseOffset = 2); >>> > } >>> > } >>> > } >>> > } >>> > rotate([90, 180, -90]) { >>> > translate([0, 0, -radius]) { >>> > bend(radius = radius, angleOffset = 90) { >>> > scale([-1, 1, 1]) { >>> > monogram(label, height = (thickness * 0.8), depth = >>> >2.01, baseOffset = 2); >>> > } >>> > } >>> > } >>> > } >>> > } >>> > } >>> >} >>> > >>> _______________________________________________ >>> OpenSCAD mailing list >>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>> >>
JB
Jordan Brown
Thu, Apr 15, 2021 4:32 PM

The real answer to this problem is to add a function that returns the
points for a particular piece of text as an array of arrays of points. 
That should be straightforward.  I'll try it after I get my current text
metrics work integrated.

The real answer to this problem is to add a function that returns the points for a particular piece of text as an array of arrays of points.  That should be straightforward.  I'll try it after I get my current text metrics work integrated.