Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to draw this picture

enter image description here

as a noob, the way I usually do (for all other images) is to painstakingly draw line by line and manually adjusting their coordinates to get the shapes I want. I have drawn several images this way and it is a soul-destroying approach.

I wonder if there is a better way to draw these types of images.

share|improve this question
3  
For TikZ, 3d isn't primitive. –  Qrrbrbirlbel Jun 26 '13 at 5:54
1  
@wereabit LOL -- Soul Destroying... Made my day. –  Nicholas Hamilton Jun 26 '13 at 6:14
    
@Qrrbrbirlbel You're right. I hadn't noticed the TikZ in the title. –  Marc van Dongen Jun 26 '13 at 6:29

1 Answer 1

up vote 8 down vote accepted

enter image description here

Perhaps, the Asymptote can help to save your soul? s.tex:

\documentclass{article}
\usepackage[inline]{asymptote}
\usepackage{lmodern}
\begin{document}
\begin{figure}
\begin{asy}
settings.prc=false;
settings.render=0;
import three;
currentprojection=orthographic(
camera=(-9,6,-6),
up=Y,
target=(0.4,0.4,-0.25),
zoom=0.5,
viewportshift=(0.25,0));

size(300,200);
size3(200,200,100);

real d=0.5;      // shift of the lower right corner of the screen  
real l=13, h=8;  // screen dimensions 

// corners of the screen 
triple scrlr=(-d,-d,0);
triple scrll=(l,scrlr.y,0);
triple scrur=(scrlr.x,h,0);
triple scrul=(scrll.x,scrur.y,0);

guide3 screen=scrlr--(scrur-2Y)--(scrur+2X-2Y)--(scrur+2X)--scrul--scrll--cycle;

pen screenPen=rgb(1,0.98,0.83);
filldraw(project(screen),screenPen,0.2*screenPen);
draw(project((scrur-2Y)--(scrur+2X)),0.2*screenPen);

// axes
draw(project(O--2X),Arrow(HookHead));
draw(project(O--2Y),Arrow(HookHead));
draw(project(O--(-2Z)),Arrow(HookHead));

label("$x$",2X,2X);
label("$y$",2Y,2Y);
label("$z$\,?",-2Z,-2Z);

// Projection
real a=3, b=4;
triple z0shift=(2,1.5,0);
triple[] z0={O,a*Y, a*Y*0.8+b*X,-a*Y*0.2+b*X}; 

guide3 sketchFront=z0[0]--z0[1]--z0[2]--z0[3]--cycle;

pen sketchPen=darkblue+1.2pt;

void drawFrame(triple[] v, pen p){
  guide3 front=v[0]--v[1]--v[2]--v[3]--cycle;
  guide3 back=v[0+4]--v[1+4]--v[2+4]--v[3+4]--cycle;
  draw(front,p);
  draw(back,p);
  for(int i=0;i<4;++i){
    draw(v[i]--v[i+4],p);  // draw front-back point connections
  } 
}

triple[] Z0=new triple[8]; // coordinates of the projected sketch
for(int i=0;i<4;++i){
  Z0[i]=shift(z0shift)*z0[i];
  Z0[i+4]=shift(z0shift)*Z0[i];
} 

triple[] Z2=copy(Z0);   // coordinates of the "normal" frame z2,
                        // as Z0 shifted evenly in Z direction
real la1=11,lb1=12;
Z2[0]-=la1*Z;
Z2[1]-=la1*Z; 
Z2[0+4]-=la1*Z;
Z2[1+4]-=la1*Z; 

Z2[2]-=lb1*Z;
Z2[3]-=lb1*Z; 
Z2[2+4]-=lb1*Z;
Z2[3+4]-=lb1*Z; 

triple[] Z1=copy(Z0);  // coordinates of the "distorted" frame z1,
Z1[0]-=  2*Z+3Z;
Z1[1]-=  3*Z+3Z; 
Z1[0+4]-=2*Z+3Z;
Z1[1+4]-=4*Z+3Z; 

Z1[2]-=2.5*Z+3Z;
Z1[3]-=  1*Z+3Z; 
Z1[2+4]-=3*Z+3Z;
Z1[3+4]-=4*Z+3Z; 

triple[] Z3=copy(Z0);  // coordinates of the "distorted" frame z3,
Z3[0]-=  3*Z+15Z;
Z3[1]-=  3*Z+15Z; 
Z3[0+4]-=3.5*Z+15Z;
Z3[1+4]-=4*Z+15Z; 
Z3[2]-=2.5*Z+15Z;
Z3[3]-=  4*Z+15Z; 
Z3[2+4]-=2.8*Z+15Z;
Z3[3+4]-=4*Z+15Z; 

drawFrame(Z0,sketchPen);
drawFrame(Z1,red+1pt);
drawFrame(Z2,darkgreen+1pt);
drawFrame(Z3,blue+1pt);

label("\{z$_1\}$",Z1[0],-X-Y);
label("\{z$_2\}$",Z2[0],-X-Y);
label("\{z$_3\}$",Z3[0],-X-Y);

// projection rays
real lproj=22;
pen projRayPen=gray+0.2pt;
for(int i=0;i<8;++i){
  draw(Z0[i]--(Z0[i]-lproj*Z),projRayPen);
}
\end{asy}
\caption{Drawing primitive shapes with \texttt{Asymptote}.}
\end{figure}
\end{document}

To process it with latexmk, create file latexmkrc:

sub asy {return system("asy '$_[0]'");}
add_cus_dep("asy","eps",0,"asy");
add_cus_dep("asy","pdf",0,"asy");
add_cus_dep("asy","tex",0,"asy");

and run latexmk -pdf s.tex.

share|improve this answer
    
Thanks for that. And more thanks for adding a bit of colors. –  wererabit Jun 26 '13 at 23:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.