Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
INWARD = -1; // text and tick alignment (used as integers)
OUTWARD = 1;
TEXT_LEFT = -1; // text justification
TEXT_CENTERED = 0;
TEXT_RIGHT = 1;
//-----
// Bend text around an arc
function ArcText(TextPath,CenterPt,Radius,BaseAngle,Justify,Orient) {
local pl = TextPath[-1].x; // path length
local c = 2*pi()*Radius;
local ta = to_deg(360 * pl / c); // subtended angle
local ja = (Justify == TEXT_LEFT ? 0deg : // assume OUTWARD
(Justify == TEXT_CENTERED) ? -ta / 2 :
(Justify == TEXT_RIGHT) ? -ta :
0deg);
ja = BaseAngle + Orient*ja;
local ArcPath = {};
local pt,r,a;
foreach(TextPath; pt) {
if (!isundef(pt.x) && !isundef(pt.y) && isundef(pt.z)) { // XY motion, no Z
r = (Orient == OUTWARD) ? Radius - pt.y : Radius + pt.y;
a = Orient * 360deg * (pt.x / c) + ja;
ArcPath += {[r*cos(a) + CenterPt.x, r*sin(a) + CenterPt.y,-]};
}
elif (isundef(pt.x) && isundef(pt.y) && !isundef(pt.z)) { // no XY, Z up/down
ArcPath += {pt};
}
else {
error("ArcText - Point is not pure XY or pure Z: " + to_string(pt));
}
}
return ArcPath;
}
@ednisley

This comment has been minimized.

Copy link
Owner Author

@ednisley ednisley commented Nov 22, 2019

More details on my blog at https://wp.me/poZKh-8AE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.