1
import graph;
import patterns;
size(300);
pair O=(0.3,-1),M=(2,.5);
real f1(real x) {return 2*cos(x);}
path Cf1=graph(f1,-3.14,3.14,n=400); 
path c1=circle(O,abs(O-M));
pair[] t=intersectionpoints(Cf1,c1);
dot("$t[0]$",t[0],W,blue); 
dot("$t[1]$",t[1],NW,green);
dot("$t[2]$",t[2],NE,red); 
dot("$t[3]$",t[3],orange);
real[][] A = intersections(Cf1,c1);
path kn10=subpath(c1,A[1][1],A[0][1]);
path kn21=subpath(c1,A[2][1],A[1][1]);
path kn01=subpath(Cf1,A[0][0],A[1][0]);
path kn12=subpath(Cf1,A[1][0],A[2][0]);
path kn23=subpath(Cf1,A[2][0],A[3][0]);
add("hatchback",hatch(NW)); 
add("Hatchback",hatch(NE));
fill(kn01--kn10--cycle,red+opacity(.5));
fill(kn21--kn12--cycle,green+opacity(.5));
fill(kn21--kn12--cycle,pattern("hatchback"));
fill(arc(O,t[3],t[2])--kn23--cycle,blue+opacity(.5));
fill(kn01--reverse(arc(O,t[2],t[1]))--kn23--reverse(arc(O,t[0],t[3]))--cycle,pattern("Hatchback"));
draw(Cf1^^c1);

enter image description here

My question: How to rotate this picture without changing the label properties?

I mean:

my output

enter image description here

but I want it like this

enter image description here

1
  • You need to save the rotation angle and un-rotate the text by the same amount. The nodes themselves should not use things like {above left] as they may also be un-rotated. Commented Mar 1, 2020 at 15:10

1 Answer 1

2

The Label command has an embed option. Following the documentation, the embed argument determines how the Label should transform with the embedding picture. By default it is Rotate, that is only shift and rotate with embedding picture.

Another possible values are Shift, Slant, Scale and Rotate(pair z).

For the question Shift is relevant since it corresponds to only shift with embedding picture.

The following code produces the initial picture and a rotated version where only the labels t[1] and t[2] are rotated.

      import graph;
      import patterns;

      size(300);
      pair O=(0.3,-1),M=(2,.5);
      real f1(real x) {return 2*cos(x);}
      path Cf1=graph(f1,-3.14,3.14,n=400);
      path c1=circle(O,abs(O-M));
      pair[] t=intersectionpoints(Cf1,c1);
      dot(Label("$t[0]$",embed=Shift),t[0],W,blue);
      dot(Label("$t[1]$"),t[1],NW,green);
      dot(Label("$t[2]$"),t[2],NE,red);
      dot(Label("$t[3]$",embed=Shift),t[3],orange);
      real[][] A = intersections(Cf1,c1);
      path kn10=subpath(c1,A[1][1],A[0][1]);
      path kn21=subpath(c1,A[2][1],A[1][1]);
      path kn01=subpath(Cf1,A[0][0],A[1][0]);
      path kn12=subpath(Cf1,A[1][0],A[2][0]);
      path kn23=subpath(Cf1,A[2][0],A[3][0]);
      add("hatchback",hatch(NW));
      add("Hatchback",hatch(NE));
      fill(kn01--kn10--cycle,red+opacity(.5));
      fill(kn21--kn12--cycle,green+opacity(.5));
      fill(kn21--kn12--cycle,pattern("hatchback"));
      fill(arc(O,t[3],t[2])--kn23--cycle,blue+opacity(.5));
      fill(kn01--reverse(arc(O,t[2],t[1]))--kn23--reverse(arc(O,t[0],t[3]))--cycle,pattern("Hatchback"));
      draw(Cf1^^c1);

      picture pic1;
      size(pic1,300);
      add(pic1,rotate(120)*currentpicture);

      shipout("rotate_example",pic1);

and the result

enter image description here

As observed by Justonly, to avoid extra output creation replace shipout("rotate_example",pic1); by the command shipout(bbox(pic1,2mm,invisible));

Another possibility is first to create a picture pic1 and then to add pic1 to the currentpicture.

2
  • Excuse me, the shipout("rotate_example",pic1); command make two outputs (one is rotate_example.pdf- this file is needed, one is <the current name file>.pdf-this file is no change). So, it is true?. Because if I replace it by (such as) shipout(bbox(pic1,2mm,invisible));, it display one output!
    – user197952
    Commented Mar 3, 2020 at 1:43
  • @justonly yes you're right
    – O.G.
    Commented Mar 3, 2020 at 7:48

You must log in to answer this question.