我想知道如何使用 Asymptote 沿弧线绘制弹簧
,import spring
并且drawspring(length,label)
只能沿直线绘制弹簧。
在 TikZ 中,沿弧线绘制弹簧是通过使用coil decorate
和绘制弧线来实现的。提前致谢
答案1
下面的功能coil
似乎可以解决问题。
settings.outformat = "pdf";
import graph;
size(5cm);
guide coil(path g, real width=0.1, real margin = 2*width) {
real L = arclength(g);
real r = width / 2;
pair startpoint = arcpoint(g, margin);
real[][] isectiontimes = intersections(g, circle(c=startpoint,r=r));
real initialcirclecentertime = (isectiontimes.length == 1 ?
isectiontimes[0][0] : isectiontimes[1][0]);
pair startdir = dir(startpoint - point(g,initialcirclecentertime));
real startangle = atan2(startdir.y, startdir.x);
real startarctime = arclength(subpath(g, 0, initialcirclecentertime));
write(startarctime);
pair endpoint = arcpoint(g, L - margin);
real finalcirclecentertime = intersections(g, circle(c=endpoint,r=r))[0][0];
pair enddir = dir(endpoint - point(g,finalcirclecentertime));
real endangle = atan2(enddir.y, enddir.x);
real endarctime = arclength(subpath(g, 0, finalcirclecentertime));
write(endarctime);
real coillength = 2r;
real lengthalongcoils = L - 2*margin;
int numcoils = ceil(lengthalongcoils / coillength);
real anglesubtended = 2pi * numcoils - startangle + endangle;
real angleat(real arctime) {
return (arctime - startarctime) * (anglesubtended / (endarctime - startarctime)) + startangle;
}
pair f(real t) {
return arcpoint(g,t) + r * expi(angleat(t));
}
return subpath(g, 0, arctime(g, margin)) & graph(f, startarctime, endarctime, n=max(length(g), 10*numcoils+2), operator..) & subpath(g, arctime(g, L-margin), length(g));
}
draw(coil(unitcircle));