6

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}
3
  • Please add a minimal working example (MWE) that illustrates your settings or a dummy example is even beneficial.
    – percusse
    Commented Sep 5, 2012 at 13:55
  • you do not need the environment TeXtoEPS. it is really outdated
    – user2478
    Commented Sep 5, 2012 at 14:19
  • Alright, will check this out! THX! Commented Sep 5, 2012 at 14:28

5 Answers 5

7

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}
1
  • 2
    +1 \usepackage[animation]{garbagecollector} No offenses meant.
    – user11232
    Commented Sep 5, 2012 at 14:12
10
\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

0
1

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}
1
  • 1
    this is the complicated variant of the simply filling, which clips internally by default.
    – user2478
    Commented Jan 4, 2013 at 11:05
1
+100

“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

0

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}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .