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 have just started learning using how to plot graphs using the TikZ package. I am still in my first steps. I appreciate if anybody can help me with the following:

I wrote the following code (see below) where I want to plot a 10x15 rectangle and then I cut a square from each corner (the square cut is the same from each corner). I want to shade each square cut (I know there is a command called filldraw but I didn't know to use it to achieve what I want), and then I want to show the dimensions of the rectangle on the graph (length is 15 and width is 10). I also want to show on the graph that the length of the square cut is "x". The reason why I want to do that is because I want to include the plot to the following problem that I intend to assign to my students during my recitation next week:

Statement of the Problem: We plan to form a 10x15 inch piece of tin into a box (without a top) by cutting a square from each corner and folding up the sides.

How much should we cut from each corner so that the volume of the resulting box is as big as possible ?

Hint: Let " x" be the length of the square cut from each corner

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (-6,0) -- (6,0);
\draw (6,0) -- (6,-6);
\draw (6,-6) -- (-6,-6);
\draw (-6,0) -- (-6,-6);
\draw (-6,-1.3) -- (6,-1.3);
\draw (6,-4.7) -- (-6,-4.7);
\draw (4.7,0) -- (4.7,-6);
\draw (-4.7,0) -- (-4.7,-6);
\end{tikzpicture}
\end{document}
share|improve this question

2 Answers 2

up vote 3 down vote accepted

One possibility:

enter image description here

The code:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[x=.5cm,y=0.5cm,>=latex]
\def\RWd{15}
\def\RHt{10}
\def\CutSide{30pt}
\draw
  (0,0) rectangle (\RWd,\RHt);
\path[draw,fill=cyan]
  (0,0) rectangle ++(\CutSide,\CutSide) 
  (\RWd,0) rectangle ++(-\CutSide,\CutSide) 
  (0,\RHt) rectangle ++(\CutSide,-\CutSide) 
  (\RWd,\RHt) rectangle ++(-\CutSide,-\CutSide);
\begin{scope}[|<->|,help lines,text=black]
\draw
  ([yshift=-13pt]0,0) -- node[fill=white] {$15$} ([yshift=-13pt]\RWd,0);   
\draw
  ([xshift=-13pt]0,0) -- node[fill=white] {$10$} ([xshift=-13pt]0,\RHt);   
\draw
  ([yshift=13pt]0,\RHt) -- node[fill=white] {$x$} ++(\CutSide,0);   
\end{scope}
\end{tikzpicture}

\end{document}

Control the height and width of the rectangle using \RHt, \RWd, respectively and the side of the cut squares using \CutSide.

share|improve this answer
    
Thanks a lot for your help! –  Pat_Ho Aug 2 at 17:13

Just for typing exercise with PSTricks.

Option 1

\documentclass[pstricks,border=12pt,12pt,dvipsnames]{standalone}
\usepackage{pgfmath}
\usepackage{pst-node}
\psset{unit=5mm,dimen=m,shortput=nab,arrows=|*-|*}

\begin{document}
\begin{pspicture}[showgrid=false](-2,-2)(15,12)
    \psframe(15,10)
    \pcline[offset=-1](0,0)(15,0)\ncput*{$15$}
    \pcline[offset=-1](0,10)(0,0)\ncput*{$10$}
    \pcline[offset=1](0,10)(2,10)\ncput*{$x$}
    \foreach \Point/\Angle in {{0,0}/0,{0,10}/-90,{15,10}/-180,{15,0}/-270}{%
        \rput{\Angle}(\Point){\psframe[fillstyle=solid,fillcolor=Gray!50](2,2)}}
\end{pspicture}
\end{document}

enter image description here

Option 2

\documentclass[pstricks,border=0pt,12pt,dvipsnames]{standalone}
\usepackage{pgfmath}
\usepackage{pst-node}
\psset{unit=5mm,dimen=m,shortput=nab,arrows=|*-|*,arcangle=-30,linejoin=2}

\begin{document}
\begin{pspicture}[showgrid=false](-2,-2)(16,11)
    \psframe(15,10)
    \pcline[offset=-1](0,0)(15,0)\ncput*{$15$}
    \pcline[offset=-1](0,10)(0,0)\ncput*{$10$}
    \psset{arrows=-}
    \foreach \Point/\Angle in {{0,0}/0,{0,10}/-90,{15,10}/-180,{15,0}/-270}{%
        \rput{\Angle}(\Point){%
            \psframe[fillstyle=solid,fillcolor=Gray!50](3,3)%
            \pcarc[linestyle=dashed](3,0)(3,3)_{\rput{*0}{$x$}}%
            \pcarc[linestyle=dashed](3,3)(0,3)_{\rput{*0}{$x$}}%
            }}
\end{pspicture}
\end{document}

enter image description here

share|improve this answer

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.