summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/asymptote/examples/spring.asy
blob: cbfb256eee4d5206e01bfc9fbd60f44f2a17c08b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
pair coilpoint(real lambda, real r, real t)
{
  return (2.0*lambda*t+r*cos(t),r*sin(t));
}
  
guide coil(guide g=nullpath, real lambda, real r, real a, real b, int n)
{
  real width=(b-a)/n;
  for(int i=0; i <= n; ++i) {
    real t=a+width*i;
    g=g..coilpoint(lambda,r,t);
  }
  return g;
}

void drawspring(real x, string label) {
  real r=8;
  real t1=-pi; 
  real t2=10*pi;
  real lambda=(t2-t1+x)/(t2-t1);
  pair b=coilpoint(lambda,r,t1);
  pair c=coilpoint(lambda,r,t2);
  pair a=b-20;
  pair d=c+20;
 
  draw(a--b,BeginBar(2*barsize()));
  draw(c--d);
  draw(coil(lambda,r,t1,t2,100));
  dot(d);

  pair h=20*I;
  draw(label,a-h--d-h,red,Arrow,Bars,PenMargin);
}