1// example file for roundedpath() in roundedpath.asy
2// written by stefan knorr
3
4
5// import needed packages
6import roundedpath;
7
8// function definition
9picture CreateKOOS(real Scale, string legend)               // draw labeled coordinate system as picture
10{
11  picture ReturnPic;
12  real S = 1.2*Scale;
13  draw(ReturnPic, ((-S,0)--(S,0)), bar = EndArrow);         // x axis
14  draw(ReturnPic, ((0,-S)--(0,S)), bar = EndArrow);         // y axis
15  label(ReturnPic, "$\varepsilon$", (S,0), SW);             // x axis label
16  label(ReturnPic, "$\sigma$", (0,S), SW);                  // y axis label
17  label(ReturnPic, legend, (0.7S, -S), NW);                 // add label 'legend'
18  return ReturnPic;                                         // return picture
19}
20
21
22// some global definitions
23real S = 13mm;                          // universal scale factor for the whole file
24real grad = 0.25;                       // gradient for lines
25real radius = 0.04;                     // radius for the rounded path'
26real lw = 2;                            // linewidth
27pair A = (-1, -1);                      // start point for graphs
28pair E = ( 1,  1);                      // end point for graphs
29path graph;                             // local graph
30pen ActPen;                             // actual pen for each drawing
31picture T[];                            // vector of all four diagrams
32real inc = 2.8;                         // increment-offset for combining pictures
33
34//////////////////////////////////////// 1st diagram
35T[1] = CreateKOOS(S, "$T_1$");                                        // initialise T[1] as empty diagram with label $T_1$
36graph = A;                                                            //  # pointwise definition of current path 'graph'
37graph = graph -- (A.x + grad*1.6, A.y + 1.6);                         //  #
38graph = graph -- (E.x - grad*0.4, E.y - 0.4);                         //  #
39graph = graph -- E;                                                   //  #
40
41graph = roundedpath(graph, radius, S);                                // round edges of 'graph' using roundedpath() in roundedpath.asy
42ActPen =  rgb(0,0,0.6) + linewidth(lw);                               // define pen for drawing in 1st diagram
43draw(T[1],                   graph, ActPen);                          // draw 'graph' with 'ActPen' into 'T[1]' (1st hysteresis branch)
44draw(T[1], rotate(180,(0,0))*graph, ActPen);                          // draw rotated 'graph' (2nd hysteresis branch)
45
46graph = (0,0) -- (grad*0.6, 0.6) -- ( (grad*0.6, 0.6) + (0.1, 0) );   // define branch from origin to hysteresis
47graph = roundedpath(graph, radius, S);                                // round this path
48draw(T[1], graph, ActPen);                                            // draw this path into 'T[1]'
49
50
51//////////////////////////////////////// 2nd diagram
52T[2] = CreateKOOS(S, "$T_2$");                                        // initialise T[2] as empty diagram with label $T_2$
53graph = A;                                                            //  # pointwise definition of current path 'graph'
54graph = graph -- (A.x + grad*1.3, A.y + 1.3);                         //  #
55graph = graph -- (E.x - grad*0.7 , E.y - 0.7);                        //  #
56graph = graph -- E;                                                   //  #
57
58graph = roundedpath(graph, radius, S);                                // round edges of 'graph' using roundedpath() in roundedpath.asy
59ActPen =  rgb(0.2,0,0.4) + linewidth(lw);                             // define pen for drawing in 2nd diagram
60draw(T[2],                   graph, ActPen);                          // draw 'graph' with 'ActPen' into 'T[2]' (1st hysteresis branch)
61draw(T[2], rotate(180,(0,0))*graph, ActPen);                          // draw rotated 'graph' (2nd hysteresis branch)
62
63graph = (0,0) -- (grad*0.3, 0.3) -- ( (grad*0.3, 0.3) + (0.1, 0) );   // define branch from origin to hysteresis
64graph = roundedpath(graph, radius, S);                                // round this path
65draw(T[2], graph, ActPen);                                            // draw this path into 'T[2]'
66
67
68//////////////////////////////////////// 3rd diagram
69T[3] = CreateKOOS(S, "$T_3$");                                        // initialise T[3] as empty diagram with label $T_3$
70graph = A;                                                            //  # pointwise definition of current path 'graph'
71graph = graph -- (A.x + grad*0.7, A.y + 0.7);                         //  #
72graph = graph -- ( - grad*0.3 , - 0.3);                               //  #
73graph = graph -- (0,0);                                               //  #
74graph = graph -- (grad*0.6, 0.6);                                     //  #
75graph = graph -- (E.x - grad*0.4, E.y - 0.4);                         //  #
76graph = graph -- E;                                                   //  #
77
78graph = roundedpath(graph, radius, S);                                // round edges of 'graph' using roundedpath() in roundedpath.asy
79ActPen =  rgb(0.6,0,0.2) + linewidth(lw);                             // define pen for drawing in 3rd diagram
80draw(T[3],                   graph, ActPen);                          // draw 'graph' with 'ActPen' into 'T[3]' (1st hysteresis branch)
81draw(T[3], rotate(180,(0,0))*graph, ActPen);                          // draw rotated 'graph' (2nd hysteresis branch)
82
83
84//////////////////////////////////////// 4th diagram
85T[4] = CreateKOOS(S, "$T_4$");                                        // initialise T[4] as empty diagram with label $T_4$
86graph = A;                                                            //  # pointwise definition of current path 'graph'
87graph = graph -- (A.x + grad*0.4, A.y + 0.4);                         //  #
88graph = graph -- ( - grad*0.6 , - 0.6);                               //  #
89graph = graph -- (0,0);                                               //  #
90graph = graph -- (grad*0.9, 0.9);                                     //  #
91graph = graph -- (E.x - grad*0.1, E.y - 0.1);                         //  #
92graph = graph -- E;                                                   //  #
93
94graph = roundedpath(graph, radius, S);                                // round edges of 'graph' using roundedpath() in roundedpath.asy
95ActPen =  rgb(0.6,0,0) + linewidth(lw);                               // define pen for drawing in 4th diagram
96draw(T[4],                   graph, ActPen);                          // draw 'graph' with 'ActPen' into 'T[4]' (1st hysteresis branch)
97draw(T[4], rotate(180,(0,0))*graph, ActPen);                          // draw rotated 'graph' (3nd hysteresis branch)
98
99
100// add some labels and black dots to the first two pictures
101pair SWW = (-0.8, -0.6);
102label(T[1], "$\sigma_f$", (0, 0.6S), NE);                             // sigma_f
103draw(T[1], (0, 0.6S), linewidth(3) + black);
104label(T[2], "$\sigma_f$", (0, 0.3S), NE);                             // sigma_f
105draw(T[2], (0, 0.3S), linewidth(3) + black);
106label(T[1], "$\varepsilon_p$", (0.7S, 0), SWW);                       // epsilon_p
107draw(T[1], (0.75S, 0), linewidth(3) + black);
108label(T[2], "$\varepsilon_p$", (0.7S, 0), SWW);                       // epsilon_p
109draw(T[2], (0.75S, 0), linewidth(3) + black);
110
111
112// add all pictures T[1...4] to the current one
113add(T[1],(0,0));
114add(T[2],(1*inc*S,0));
115add(T[3],(2*inc*S,0));
116add(T[4],(3*inc*S,0));
117
118
119// draw line of constant \sigma and all intersection points with the graphs in T[1...4]
120ActPen = linewidth(1) + dashed + gray(0.5);                           // pen definition
121draw((-S, 0.45*S)--((3*inc+1)*S, 0.45*S), ActPen);                    // draw backgoundline
122label("$\sigma_s$", (-S, 0.45S), W);                            // label 'sigma_s'
123
124path mark = scale(2)*unitcircle;                                  // define mark-symbol to be used for intersections
125ActPen = linewidth(1) + gray(0.5);                                    // define pen for intersection mark
126draw(shift(( 1 - grad*0.55 + 0*inc)*S, 0.45*S)*mark, ActPen);         //  # draw all intersections
127draw(shift((-1 + grad*1.45 + 0*inc)*S, 0.45*S)*mark, ActPen);         //  #
128draw(shift(( 1 - grad*0.55 + 1*inc)*S, 0.45*S)*mark, ActPen);         //  #
129draw(shift(( 1 - grad*0.55 + 2*inc)*S, 0.45*S)*mark, ActPen);         //  #
130draw(shift((     grad*0.45 + 2*inc)*S, 0.45*S)*mark, ActPen);         //  #
131draw(shift((     grad*0.45 + 3*inc)*S, 0.45*S)*mark, ActPen);         //  #
132