Created
November 22, 2019 21:57
-
-
Save ednisley/652e61aadd2a7c45339aadf42b0f31b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More details on my blog at https://wp.me/poZKh-8AE