How to draw this pyramid with TeX?

General Update

I can suggest two answers, the first one with tikz-3dplot interesting because we draw the pyramid in 3D and we can change easily the point of view and the perspective; the second one with tkz-euclide in 2D with parallel projection.

I made some mistakes in my first calculations but there are two problems to draw a correct figure. The first problem is to place E and K, the second one is to place H. The methods depend of the tools used, 3D or 2D with parallel projection.

How to place K and E

BK is orthogonal to the plane SCD, ABKE is a parallelogram, so AE||BK then AE is orthogonal to SCD. AE is perpendicular to SD in the plane ASD. This method is useful with with parallel projection because ASD is the main front and is in the main plane. We can use a projection in a plane to place E.

In 3D with for example tikz-3dplot we need to calculate the coordinate of E. I named \a the side of the square ABCD.

enter image description here

The coordinates of E are (0,2*\a/3,sqrt(2)/3*\a). Remark: If the coordinates of K are (xK,yK,zK) then the coordinates of E are (0,yK,zK). Or xK=xB, so K is defined by (\a,2*\a/3,sqrt(2)/3*\a).

About K. In the first answer, I used the code from of Caramdir's answer (from this question). If you know the equation of a plane, it's possible to determine the orthognal projection of a point on this plane. I determined the coordinates of K, so I can avoid the interesting code of Caramdir. Remark: SCD has an simple equation here sqrt(2)y+z = sqrt(2)\s it's parallel to (AB) and cut axis in S and D. It's easy to get K with caramdir's code.

How to place H

H is the projection orthogonal of A on OS. OAS is orthogonal to ABCD. The projection orthognal of H on ABBCD is a point Q on the line OA. Below I determined the coordinates of Q (2/5 \a,2/5 /a,0)and then I determined the coordinates of H. It's not possible to use the orthogonal projection of TikZ.

enter image description here

Part 1) With tikz-3dplot

 \documentclass{article}
 \usepackage{tikz}
 \usepackage{tikz-3dplot}
 \usetikzlibrary{intersections,calc}


 \tikzset{ hidden/.style = {thin, dotted}}
   \tikzset{%
     add/.style args={#1 and #2}{
         to path={%
  ($(\tikztostart)!-#1!(\tikztotarget)$)--($(\tikztotarget)!-#2!(\tikztostart)$)%
   \tikztonodes}}}

 \begin{document}

 %\tdplotsetmaincoords{60}{120}
  \tdplotsetmaincoords{80}{100} 
 \begin{tikzpicture}[tdplot_main_coords,scale=2]
 \pgfmathsetmacro\a{2}

 % definitions 
    \path (0,0,0)                           coordinate (A) 
          (\a,0,0)                          coordinate (B) 
          (\a,\a,0)                         coordinate (C) 
          (0,\a,0)                          coordinate (D) 
          (0,0,{\a*sqrt(2)})                coordinate (S) 
          (0,0,{0.5*\a*sqrt(2)})            coordinate (M) 
          (0.5*\a,0.5*\a,0)                 coordinate (O) 
          (0,0.5*\a,{0.5*\a*sqrt(2)})       coordinate (I) 
          (2/5*\a,2/5*\a,{sqrt(2)/5*\a})    coordinate (H)
          ($(B)!2!(M)$)                     coordinate (N)
          (0,2*\a/3,{sqrt(2)/3*\a})         coordinate (E)
           (\a,2*\a/3,{sqrt(2)/3*\a})        coordinate (K) ;
 % drawing
 \begin{scope}
    \clip (S) -- (B) -- (D) --cycle;
    \draw[hidden] (B) -- (N);
 \end{scope}
 \begin{scope}
    \clip (S) -- (I) -- (N) --cycle;
    \draw (B) -- (N);
 \end{scope}

 \draw[hidden] 
       (A) -- (C)  (A) -- (B)  (A) -- (D) (A) -- (H) (A) -- (S)
      (A) -- (E) (B) -- (D)  (O) -- (S) (I) -- (M);
 \draw (B) -- (K) -- (E)   (C) -- (N) -- (K)
       (B) --(C) -- (D) (S) -- (D)  (S) -- (B)  (S) -- (C);
 \draw[add = 1 and 1]  (S) to (N); 

 % place black circles and labels
 \foreach \point/\position in {A/left,B/left,C/right,D/right,E/right,H/above,
   I/right,K/right,M/right,N/left,O/right,S/left}
 {
   \fill (\point) circle (.5pt);
   \node[\position=3pt] at (\point) {$\point$};
 }

 \end{tikzpicture}
 \end{document}

enter image description here

If you want to change the point of view you can try \tdplotsetmaincoords{60}{120}.

enter image description here

Part B) with tkz-euclide

If you want to use only TikZ, see Gonzalo's answer. The problem are the same, only the syntax and the macros are different. But the answers are similar. It's not very easy to show 3D objects with 2D methods.

I use the projection of A on SD to get E but it's also possible to get the coordinates. It's more difficult to get H, I used here the fact SO=5*OH.

 \documentclass{article}
 \usepackage{tkz-euclide,amsmath} 
 \usetkzobj{all} 
 \tikzset{hidden/.style = {thin, dotted}}
 \begin{document}

 \begin{tikzpicture}
  \tkzInit[xmin=-5,xmax=10,ymin=-5,ymax=15]
   \tkzClip
  \pgfmathsetmacro\zs{3+5*sqrt(2)}
  % definition
  \tkzDefPoints{0/0/B,1/3/A,5/0/C,6/3/D,1/\zs/S}
  \tkzDefMidPoint(A,C)                      \tkzGetPoint{O}
  \tkzDefMidPoint(S,A)                      \tkzGetPoint{M}
  \tkzDefMidPoint(S,D)                      \tkzGetPoint{I}
  \tkzDefPointBy[projection=onto S--D](A)   \tkzGetPoint{E} 
  \tkzDefPointWith[colinear= at E](A,B)     \tkzGetPoint{K}
  \tkzDefPointWith[linear,K=2](C,I)         \tkzGetPoint{N}
  \tkzDefPointWith[linear,K=1/5](O,S)       \tkzGetPoint{H}
 % drawing 
  \tkzDrawSegments[hidden](A,B A,D I,M A,C B,D S,O M,E A,E A,S  A,H)
  \tkzDrawSegments(B,C C,D B,S S,D B,K K,E C,N K,N)
   \begin{scope}
       \tkzClipPolygon(S,B,D) 
       \tkzDrawSegments[hidden](B,N)
   \end{scope}
   \begin{scope}
      \tkzClipPolygon(S,I,N) 
       \tkzDrawSegments(B,N)
   \end{scope}
   % labels
    \tkzDrawPoints(A,B,C,D,S,I,M,O,E,K,N,H)
    \tkzLabelPoints(A,B,C,D,K,O)
    \tkzLabelPoints[above](S,E,N,H)
    \tkzLabelPoints[above right](I,M)
    \tkzMarkRightAngles(A,E,D D,A,S)
 \end{tikzpicture}
 \end{document}

enter image description here


With PSTricks.

enter image description here

\documentclass[pstricks]{standalone}
\usepackage{pst-eucl}
\psset{linejoin=1}
\begin{document}
\begin{pspicture}[showgrid=false](-.75,-.75)(5.75,9.75)
    \pstGeonode[PosAngle={-135,-45,0,180,180,0}]
        {B}(4,0){C}(5,2){D}(1,2){A}(1,7){S}([nodesep=1.8]{S}D){E}
    \pstMiddleAB{D}{B}{O}
    \pstTranslation[PosAngle=30]{A}{B}{E}[K]
    \pstProjection{O}{S}{A}[H]
    \pstMiddleAB[PosAngle=-45]{S}{A}{M}
    \pstMiddleAB{S}{D}{I}
    \pstInterLL{B}{M}{C}{I}{N}
    \pstInterLL[PointName=none,PointSymbol=none]{D}{S}{B}{N}{X}
    \psline(B)(C)(D)
    \psline(B)(K)(E)
    \psline(B)(S)(D)
    \psline(C)(N)(K)
    \psline(X)(N)
    \pcline[nodesepA=-2,nodesepB=-.5](S)(N)
    \psset{linestyle=dashed}
    \pspolygon(A)(B)(D)
    \pspolygon(A)(C)(D)
    \psline(A)(S)(O)
    \psline(H)(A)(E)
    \psline(M)(I)
    \psline(B)(X)
\end{pspicture}
\end{document}

Here's one possibility:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,intersections,calc}

\def\xmov{0.8cm}
\def\ymov{3cm}
\def\xside{4.5cm}

\begin{document}

\begin{tikzpicture}
\clip (-0.5,-0.5) rectangle (5.7,12.1);
\coordinate (b);
\coordinate[above right=\ymov and \xmov of b] (a);
\coordinate[right=\xside of b] (c);
\coordinate[right=\xside of a] (d);
\coordinate[above=6cm of a] (s);
\draw (b) -- (s) -- (c);
\draw[name path=edge1] (s) -- (d);
\draw[dashed] (b) -- (a) -- (d) -- (c) -- (b) -- (d);
\draw[dashed,name path=diag1] (b) -- (d);
\draw[dashed,name path=diag2] (a) -- (c);
\draw[dashed] (s) -- (a);
\coordinate[name intersections={of=diag1 and diag2,by={o}}];
\draw[dashed] (s) -- (o);
\coordinate (i) at ( $ (s)!0.5!(d) $ );
\coordinate (m) at ( $ (s)!0.5!(a) $ );
\path[dashed,name path=line1] (b) -- ( $ (b)!15cm!(m) $ );
\path[draw,name path=line2] (c) -- ( $ (c)!15cm!(i) $ );
\coordinate[name intersections={of=line1 and line2,by={n}}];
% intersection od sd with nb
\coordinate[name intersections={of=line1 and edge1,by={aux}}];
\coordinate (e) at ( $ (d)!(a)!(s) $ );
\coordinate[below left=\ymov and \xmov of e] (k);
\coordinate (h) at ($(s)!(a)!(o)$);
\draw (n) -- (aux);
\draw[dashed] (aux) -- (b);
\draw[dashed] (a) -- (h);
\draw (e) -- (k) -- (b);
\draw[dashed] (e) -- (a);
\draw (n) -- (k);
\draw (n) -- ( $ (n)!6cm!(s) $ );
% place black circles and labels
\foreach \point/\position in {a/left,b/left,c/right,d/right,e/right,h/above left,
  i/right,k/right,m/right,n/left,o/right,s/left}
{
  \fill (\point) circle (2pt);
  \node[\position=2pt] at (\point) {$\point$};
}
\end{tikzpicture}

\end{document}

enter image description here

Midpoints were obtained using ($(s)!0.5!(o)$) and the projection was obtained with ($(s)!(a)!(o)$). Intersections were calculated with the intersections library.

Changing dashed to dotted everywhere in the code above one gets:

enter image description here

Tags:

Tikz Pgf