Generalshear macros: rotatebox and scalebox are so primitive

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
brac37
Posts: 5
Joined: Fri Jan 21, 2011 12:03 am

shear macros: rotatebox and scalebox are so primitive

Post by brac37 »

rotatebox and scalebox are macros of the graphicx package. They are primitive in both senses, i.e. they are (1) limited and (2) generating.

Ok, that was the theoretical part. The practical part consists of two macros built on rotatebox and scalebox.

Code: Select all

\usepackage{graphicx}

%\hshearbox{vertical_prescale_times_shearfactor}{one_divide_by_shearfactor}{content}
% an initial vertical downscale is often necessary for a 3d projection
\newcommand{\hshearbox}[3]{\scalebox{0.866025}[#2]{\rotatebox{210}%
{\scalebox{1.73205}[-0.57735]{\rotatebox{60}{\scalebox{-1.1547}[#1]{#3}}}}}}

%\vshearbox{horizontal_prescale_times_shearfactor}{one_divide_by_shearfactor}{content}
% an initial horizontal downscale is often necessary for a 3d projection
\newcommand{\vshearbox}[3]{\scalebox{#2}[0.866025]{\rotatebox{210}%
{\scalebox{-0.57735}[1.73205]{\rotatebox{60}{\scalebox{#1}[-1.1547]{#3}}}}}}
One can use the fp package if one is to lazy for elementary computations.

But maybe, there is a more direct way to do shear transforms.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

brac37
Posts: 5
Joined: Fri Jan 21, 2011 12:03 am

shear macros: rotatebox and scalebox are so primitive

Post by brac37 »

Here is an example.

Code: Select all

\documentclass{article}

\usepackage{graphicx,pstricks}

%\hshearbox{vertical_prescale_times_shearfactor}{one_divide_by_shearfactor}{content}
% an initial vertical downscale is often necessary for a 3d projection
\newcommand{\hshearbox}[3]{\scalebox{0.866025}[#2]{\rotatebox{210}%
{\scalebox{1.73205}[-0.57735]{\rotatebox{60}{\scalebox{-1.1547}[#1]{#3}}}}}}
%\vshearbox{horizontal_prescale_times_shearfactor}{one_divide_by_shearfactor}{content}
% an initial horizontal downscale is often necessary for a 3d projection
\newcommand{\vshearbox}[3]{\scalebox{#2}[0.866025]{\rotatebox{210}%
{\scalebox{-0.57735}[1.73205]{\rotatebox{60}{\scalebox{#1}[-1.1547]{#3}}}}}}

\newcommand{\tilenamebox}[1]{\rput[B]{0}(0,-2.5pt){$#1$}}
\newcommand{\tilestack}[3]{\begin{array}{@{}c@{}}\begin{picture}(42,55)(4,0)
\put(25,50){\hshearbox{0.333333}{1}{\tilenamebox{#1}}}
\put(20,37.5){\tilenamebox{#1}}
\put(40,42.5){\vshearbox{-0.333333}{-1}{\tilenamebox{#1}}}
\put(20,22.5){\tilenamebox{#2}}
\put(40,27.5){\vshearbox{-0.333333}{-1}{\tilenamebox{#2}}}
\put(20,07.5){\tilenamebox{#3}}
\put(40,12.5){\vshearbox{-0.333333}{-1}{\tilenamebox{#3}}}
\multiput(5,0)(0,15){4}{\line(1,0){30}\line(1,1){10}}
\put(05,45){\line(0,-3){45}\line(1,1){10}}
\put(35,45){\line(0,-3){45}}
\put(15,55){\line(1,0){30}\line(0,-1){45}}
\multiput(9,46)(2,0){13}{\hshearbox{1}{1}{\makebox(0,0)[lb]{\line(0,1){1.5}}}}
\multiput(17,54)(2,0){13}{\hshearbox{1}{1}{\makebox(0,0)[rt]{\line(0,-1){1.5}}}}
\end{picture}\end{array}}

\begin{document}
$$
\tilestack{y}{a}{b} \qquad \mbox{and} \qquad \tilestack{b}{a}{y}
$$
\end{document}
Post Reply