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.

Is there an easy way to draw a triangle like the one on the picture with PSTricks? Maybe a method for calculating the position of the outer line for specific height?

Example Image

I'm using the environment in this dummy-example:

\documentclass[letterpaper,dvips]{article}

\usepackage[utf8]{inputenc}
\usepackage{textcomp}

\usepackage{pst-all}
\usepackage{pst-eps}

\usepackage{color}

\begin{document}

\pagestyle{empty}
\begin{TeXtoEPS}
\fontfamily{phv}\selectfont
\psset{xunit=1cm,yunit=1cm,runit=1cm}
\begin{pspicture}(10,10)


\end{pspicture}

\end{TeXtoEPS}

\end{document}
share|improve this question
    
Please add a minimal working example (MWE) that illustrates your settings or a dummy example is even beneficial. –  percusse Sep 5 '12 at 13:55
    
you do not need the environment TeXtoEPS. it is really outdated –  Herbert Sep 5 '12 at 14:19
    
Alright, will check this out! THX! –  PascalTurbo Sep 5 '12 at 14:28

5 Answers 5

up vote 6 down vote accepted

enter image description here

\documentclass[border=12pt,pstricks]{standalone}
\usepackage{multido}
\begin{document}
\begin{pspicture}[showgrid=false](6,-6)
\multido{\iy=-1+-1,\nw=1+1,\nh=1+1}{6}{\pstriangle(3,\iy)(\nw,\nh)}
\end{pspicture}
\end{document}

Animated version:

enter image description here

\documentclass[border=12pt,pstricks]{standalone}
\usepackage{multido}
\begin{document}
\multido{\iy=-1+-1,\nw=1+1,\nh=1+1}{6}{%
\begin{pspicture}[showgrid=false](6,-6)
\pstriangle(3,\iy)(\nw,\nh)
\end{pspicture}}
\end{document}
share|improve this answer
2  
+1 \usepackage[animation]{garbagecollector} No offenses meant. –  Harish Kumar Sep 5 '12 at 14:12
    
@HarishKumar: Thanks for the upvote. –  Oh my ghost Sep 5 '12 at 14:16
    
Great solution. Thank you very much! –  PascalTurbo Sep 5 '12 at 14:24
    
I just got a down vote. Thanks! –  Oh my ghost Jan 4 '13 at 11:39
\documentclass[border=12pt,pstricks]{standalone}
\usepackage{pstricks}
\begin{document}
\begin{pspicture}(12,6)
\pspolygon[fillstyle=hlines,hatchangle=0,hatchsep=1cm](0,0)(6,0)(3,6)
\pstriangle[fillstyle=hlines,hatchangle=0,hatchsep=1cm,hatchcolor=red](9,0)(6,6)
\end{pspicture}
\end{document}

enter image description here

share|improve this answer
2  
+1 for the trick with hatching. –  Oh my ghost Sep 5 '12 at 14:55

“Just for fun with” TikZ …

Code (three arbitrary coordinates)

\documentclass[tikz]{standalone}
\newcommand*{\triangleBaseWidth}{2cm}
\newcommand*{\triangleHeight}{2cm}
\newcommand*{\triangleCountOfLines}{5}% for non-animation

\usetikzlibrary{calc}% for ($()!!()$) calculation
\begin{document}
\foreach \triangleCountOfLines in {1,...,10}{% animation
\begin{tikzpicture}[font=\tiny]
\path   (0,0)                                  coordinate (A)
      + (\triangleBaseWidth,0)                 coordinate (B)
      + (\triangleBaseWidth/2,\triangleHeight) coordinate (C);% the triangle's points

\draw (A) --
         node[below] {$n = \triangleCountOfLines$}% n = ?
      (B) -- (C) -- cycle;% the triangle

\foreach \l in {1,...,\triangleCountOfLines}{% horizontal lines
    \draw ($(C)!\l/(\triangleCountOfLines+1)!(A)$) -- ($(C)!\l/(\triangleCountOfLines+1)!(B)$);
}

\foreach \c/\p in {A/left,B/right,C/above}{% labels of coordinates
    \fill (\c) circle (.8pt) node[\p] {\c};
}
\end{tikzpicture}
}% animation
\end{document}

Output

enter image description here

Code (isosceles triangle shape)

\documentclass[tikz]{standalone}
\newcommand*{\triangleBaseWidth}{2cm}
\newcommand*{\triangleHeight}{2cm}
\newcommand*{\triangleCountOfLines}{5}     % for non-animation

\usetikzlibrary{calc}                      % for ($()!!()$) calculation
\usetikzlibrary{shapes.geometric}          % for the isosceles triangle

\begin{document}
\foreach \triangleCountOfLines in {1,...,10}{% animation
\begin{tikzpicture}[font=\tiny]
\node[
    isosceles triangle,
    anchor=center,
    draw,
    rotate=90,
    minimum width=\triangleBaseWidth,
    minimum height=\triangleHeight,
    inner sep=0pt,
    ] (3) at (0,0) {};

\node[below] at (3.lower side) {$n = \triangleCountOfLines$};% n = ?

\begin{scope}
    \clip (3.left corner) -- (3.right corner) -- (3.apex) -- cycle;
    \foreach \l in {1,...,\triangleCountOfLines}{% horizontal lines
        \draw ($(3.apex)!\l/(\triangleCountOfLines+1)!(3.left corner)$) -- ($(3.apex)!\l/(\triangleCountOfLines+1)!(3.right corner)$);
    }
\end{scope}
\end{tikzpicture}
}% animation
\end{document}

Output

enter image description here

share|improve this answer

An overkill solution with the Homothetie macro provided in pst-eucl package.

enter image description here

\documentclass[border=12pt,pstricks]{standalone}
\usepackage{multido}
\usepackage{pst-eucl}

\begin{document}
\begin{pspicture}[showgrid=false](6,-6)
\psset{PointName=none,PointSymbol=none}
\pstGeonode[CurveType=polygon](3,0){A}(0,-6){B}(6,-6){C}
\multido{\n=0.166+0.166}{5}
{   
    \pstHomO[HomCoef=\n]{A}{B,C}
    \pstLineAB{B'}{C'}
}
\end{pspicture}
\end{document}

Forgot to attach the animated one:

enter image description here

\documentclass[border=12pt,pstricks]{standalone}
\usepackage{multido}
\usepackage{pst-eucl}

\begin{document}
\multido{\n=0.166+0.166}{5}{%   
\begin{pspicture}[showgrid=false](6,-6)
\psset{PointName=none,PointSymbol=none}
\pstGeonode[CurveType=polygon](3,0){A}(0,-6){B}(6,-6){C}
    \pstHomO[HomCoef=\n]{A}{B,C}
    \pstLineAB{B'}{C'}
\end{pspicture}}
\end{document}
share|improve this answer

A clipping method:

enter image description here

\documentclass[border=12pt,pstricks]{standalone}

\begin{document}
\pspicture(6,-6)
    \psclip{\pstriangle(3,-6)(6,6)}
        \multips(0,-1)(0,-1){5}{\psline(6,0)}
    \endpsclip
\endpspicture
\end{document}
share|improve this answer
1  
this is the complicated variant of the simply filling, which clips internally by default. –  Herbert Jan 4 '13 at 11:05

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.