2016년 10월 2일 일요일

LaTeX compatible graphics with Asymptote




 I wanted to make some graphics for some posts, especially while I was writing about SO(3) generators and it's Lie Algebra, so I googled some graphic tools compatible with $\LaTeX$ and I discovered Asymptote.  It produces high quality SVG, PDF, etc which is also compatible with $\LaTeX$, and it's great than I thought at my first sight.




 I struggled a lot for the first time realizing how to compile, or using the right syntax because it wasn't actually 'easy' to use, so I googled some wikis and tutorials. Playing with some codes and tutorials, now I think it's way better. Below is the code for a graphic that will be used in my later posts, showing the rotation which the z-axis is invariant.



1:  settings.outformat = "png" ;  
2:  settings.render = 32 ;  
3:  import three;  
4:    
5:  size(4cm);  
6:  currentprojection=perspective(1,1,0.7,up=Z);  
7:    
8:  //regular axis  
9:  draw( O -- X, L=Label("$x$", position = EndPoint) ,  
10:     arrow=Arrow3(emissive(black)));  
11: draw( O -- Y, L=Label("$y$", position = EndPoint) ,  
12:     arrow=Arrow3(emissive(black)));  
13: draw( O -- Z, L=Label("$z$", position = EndPoint) ,  
14:     arrow=Arrow3(emissive(black)));  
15:    
16:    
17:  //transformed axis  
18:  draw( O -- cos(0.3)*X+sin(0.3)*Y,  
19:     L = Label( scale(0.3) * "$R_{z}(\theta)|x\rangle$",  
20:           position = EndPoint) ,   
21:     arrow=Arrow3(emissive(red)),   
22:     red);  
23:    
24:  draw( O -- cos(0.3)*Y-sin(0.3)*X,  
25:     L = Label( scale(0.3) * "$R_{z}(\theta)|y\rangle$",  
26:         position = EndPoint) ,  
27:     arrow=Arrow3(emissive(red)),red);  
28:    
29:    
30:  //angle representation  
31:  draw( arc(c=O, 0.2*X, 0.2*cos(0.3)*X+0.2*sin(0.3)*Y),   
32:     red+linewidth(0.3pt) );  
33:  draw( arc(c=O, 0.2*Y, 0.2*cos(0.3)*Y-0.2*sin(0.3)*X),   
34:     red+linewidth(0.3pt) );  
35:    
36:  dot(O);  


  The result was the below one.


  

  The best thing about Asymptote is that it is greatly compatible with $\LaTeX$. Using the command usepackage in $\LaTeX$ will make it available to use Asymptote in it, so that we can draw graphics while writing the words. And as Asymptote uses TeX fonts, there is font consistency when it's used with $\LaTeX$. 

 I'm still not so familiar and there's tons of things to learn more about it's functions and syntax, but it will be a great merit when I need to plot or design graphics while using $\LaTeX$. I hope you guys would find it useful too.


댓글 없음:

댓글 쓰기