Graphics, Figures & TablesTikZ: \foreach applied to rotated axes

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Sundial
Posts: 57
Joined: Thu Apr 19, 2012 7:28 pm

TikZ: \foreach applied to rotated axes

Post by Sundial »

Arrows _improperly_ drawn. Instead of along the new axis z, TikZ places them over x-axis. Where is my fault? Thanks in advance for the appropriate drifts.

Code: Select all

% --------- inc.tex --------- Apr.23,2015 ---------
\documentclass{article}
\usepackage{tikz}             

\usepackage[active,tightpage]{preview}
\PreviewEnvironment{center}
\setlength\PreviewBorder{10pt}%

\tikzstyle{load}   = [thick,-latex]
\tikzstyle{stress} = [-latex]
\tikzstyle{dim}    = [latex-latex]
\tikzstyle{axis}   = [-latex,blue!55]

\tikzstyle{two}=[x={(1cm,0cm)},y={(0cm,1cm)}]
\tikzstyle{three}=[x={(0.5547cm,0.83205cm)},y={(-0.83205cm,0.5547cm)}]

\begin{document}
\begin{center}
  \begin{tikzpicture}
    \coordinate (O) at (0,0);
     \draw[axis,two] (O) -- ++(5.5,0) node[right] {$x$};
     \draw[axis,two] (O) -- ++(0,5) node[above] {$y$};
%
% Contour
  \draw[red] (-0.83205,0.5547) -- (2,3); % triangular load shape
  \draw[red] (-0.83205,0.5547) -- (0,0); % ditto
    
    \draw[ultra thick] (0,0) -- ++(2,3);  % beam-1-inclined
    \draw[ultra thick] (2,3) -- ++(2,0);  % beam-2-horizontal
%   
    \draw[dim] (4.5,0) -- ++(0,3) node[midway,right] {$h$}; % column dimension
    \draw (4.25,3) -- ++(0.5,0); 
%    
    \draw[dim] (0,-0.5) -- ++(4,0) node[midway,above] {$\ell$}; % beam dimension
    \draw (4,-0.75) -- ++(0,0.5); 
    \draw (0,-0.75) -- ++(0,0.5); 
%
 \draw[dim] (0,4) -- ++(2,0) node[midway,above] {$\ell_1$};
 \draw[dim] (2,4) -- ++(2,0) node[midway,above] {$\ell_2$}; 
 \draw (2,3.75) -- ++(0,0.5);
 \draw (4,3.75) -- ++(0,0.5);

% ==================== Rotated axes ====================================
%^^^^^^^^^^^^^^^^^^^^^ 
 \draw[axis,three] (O) -- ++(4.5,0) node[right] {$z$};
 \draw[axis,three] (O) -- ++(0,2) node[above] {$w$};  
%^^^^^^^^^^^^^^^^^^^^^ 

% Tentative to fill red triangle with group of arrows
% up to now _improperly_ drawn: on x-axis instead of z-axis
\foreach \z in {0,0.25,...,3.0} {%
\draw[-latex] (\z,-1/3.605*\z + 1) -- (\z,0);}
% 
\end{tikzpicture} %
\end{center}
\end{document}
% ---- EOF: inc.tex ----
Attachments
05.png
05.png (15.5 KiB) Viewed 8210 times

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10334
Joined: Mon Mar 10, 2008 9:44 pm

TikZ: \foreach applied to rotated axes

Post by Stefan Kottwitz »

Nice to see another TikZ question!

It's easy to shift and rotate with TiKZ. Here I simply apply a rotation and it visually fits:

Code: Select all

\foreach \z in {0,0.25,...,3.0} {%
\draw[-latex,rotate=56] (\z,-1/3.605*\z + 1) -- (\z,0);}
rotation.png
rotation.png (15.69 KiB) Viewed 8195 times
Stefan
LaTeX.org admin
Sundial
Posts: 57
Joined: Thu Apr 19, 2012 7:28 pm

TikZ: \foreach applied to rotated axes

Post by Sundial »

Wow, Stefan! So great and useful. Thank you very much
Sundial
Posts: 57
Joined: Thu Apr 19, 2012 7:28 pm

TikZ: \foreach applied to rotated axes

Post by Sundial »

Hi,Stefan,just to upload the whole code after your precious drifts and ask you a further (and last, no more, believe me) question: how to translate the att'd figure from (0,0) to (2,3), coordinates of left-bottom point. Thx&cheers

Code: Select all

% --------- inc.tex --------- Apr.23,2015 ---------
\documentclass{article}
\usepackage{tikz}             

\usepackage[active,tightpage]{preview}
\PreviewEnvironment{center}
\setlength\PreviewBorder{10pt}%

\tikzstyle{load}   = [thick,-latex]
\tikzstyle{stress} = [-latex]
\tikzstyle{dim}    = [latex-latex]
\tikzstyle{axis}   = [-latex,blue!55]

\tikzstyle{two}=[x={(1cm,0cm)},y={(0cm,1cm)}]
\tikzstyle{three}=[x={(0.5547cm,0.83205cm)},y={(-0.83205cm,0.5547cm)}]

\begin{document}
\begin{center}
  \begin{tikzpicture}
    \coordinate (O) at (0,0);
     \draw[axis,two,dashed] (O) -- ++(5.5,0) node[right] {$x$};
     \draw[axis,two,dashed] (O) -- ++(0,5) node[above] {$y$};
%
% Draw structural elements
    \draw[ultra thick] (0,0) -- ++(2,3);  % beam-1-inclined
    \draw[ultra thick] (2,3) -- ++(2,0);  % beam-2-horizontal
%          
% ============= Create Arrows and Rotate to inclined beam ==============
\foreach \z in {0,0.25,...,3.0} {%
\draw[-latex,rotate=56.31] (\z,-1/3.6055*\z + 1) -- (\z,0);}
% Contour
 \draw[red,rotate=56.31] (0,1) -- (3.60,0); % triangular load shape
% ====================================================================== 
%   
    \draw[dim] (4.5,0) -- ++(0,3) node[midway,right] {$h$}; % column dimension
    \draw (4.25,3) -- ++(0.5,0); 
    \draw (4.25,0) -- ++(0.5,0);
%    
    \draw[dim] (0,-0.5) -- ++(4,0) node[midway,above] {$\ell$}; % beam dimension
    \draw (4,-0.75) -- ++(0,0.5); 
    \draw (0,-0.75) -- ++(0,0.5); 
%
 \draw[dim] (0,4) -- ++(2,0) node[midway,above] {$\ell_1$};
 \draw[dim] (2,4) -- ++(2,0) node[midway,above] {$\ell_2$}; 
 \draw (0,3.75) -- ++(0,0.5);
 \draw (2,3.75) -- ++(0,0.5);
 \draw (4,3.75) -- ++(0,0.5);
% 
\end{tikzpicture} %
\end{center}
\end{document}
% ---- EOF: inc.tex ----
Attachments
01.png
01.png (14.6 KiB) Viewed 8183 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10334
Joined: Mon Mar 10, 2008 9:44 pm

TikZ: \foreach applied to rotated axes

Post by Stefan Kottwitz »

Sundial wrote:ask you a further (and last, no more, believe me) question
I would be disappointed! I hope for more interesting questions. Questions are the blood in the heart of the forum. No questions, no life. No answers, nothing to find for people googling for help.
Sundial wrote:how to translate the att'd figure from (0,0) to (2,3), coordinates of left-bottom point.
You could use a scope with shift, such as

Code: Select all

\begin{scope}[xshift=2cm, yshift=3cm]
...
\end{scope}
Stefan
LaTeX.org admin
Sundial
Posts: 57
Joined: Thu Apr 19, 2012 7:28 pm

TikZ: \foreach applied to rotated axes

Post by Sundial »

Superb, Stefan, as per code attachment. So, being my "blood flowing" around the interesting matter, could you please let me know how may I perform the rotation shown in the figure? Thanks again.

Code: Select all

% --------- shi.tex --------- Apr.24,2015 ---------
\documentclass{article}
\usepackage{tikz}             

\usepackage[active,tightpage]{preview}
\PreviewEnvironment{center}
\setlength\PreviewBorder{10pt}%

\tikzstyle{load}   = [thick,-latex]
\tikzstyle{stress} = [-latex]
\tikzstyle{dim}    = [latex-latex]
\tikzstyle{axis}   = [-latex,blue!55]

\tikzstyle{two}=[x={(1cm,0cm)},y={(0cm,1cm)}]
\tikzstyle{three}=[x={(0.5547cm,0.83205cm)},y={(-0.83205cm,0.5547cm)}]

\begin{document}
\begin{center}
  \begin{tikzpicture} [two]
    \coordinate (O) at (0,0);
     \draw[axis,two,dashed] (O) -- ++(5.5,0) node[right] {$x$};
     \draw[axis,two,dashed] (O) -- ++(0,5) node[above] {$y$};
%
% Draw structural elements
    \draw[ultra thick] (0,0) -- ++(2,3);  % beam-1-inclined
    \draw[ultra thick] (2,3) -- ++(2,0);  % beam-2-horizontal
%          
% ============= Create Arrows and Rotate to inclined beam ==============
\foreach \z in {0,0.25,...,3.0} {%
\draw[-latex,rotate=56.31] (\z,-1/3.6055*\z + 1) -- (\z,0);}
% Contour
 \draw[red,rotate=56.31] (0,1) -- (3.60,0); % triangular load shape
% ====================================================================== 
% ============== Group translated ============
\begin{scope}[xshift=2cm, yshift=3cm]
\foreach \z in {0,0.25,...,1.5} {%
\draw[-latex] (\z,-1/2*\z + 1) -- (\z,0);}
% Contour
 \draw[red] (0,1) -- (2,0);  %-- (0,0) ;
\end{scope}
% ============================================

%   
    \draw[dim] (4.5,0) -- ++(0,3) node[midway,right] {$h$}; % column dimension
    \draw (4.25,3) -- ++(0.5,0); 
    \draw (4.25,0) -- ++(0.5,0);
%    
    \draw[dim] (0,-0.5) -- ++(4,0) node[midway,above] {$\ell$}; % beam dimension
    \draw (4,-0.75) -- ++(0,0.5); 
    \draw (0,-0.75) -- ++(0,0.5); 
%
 \draw[dim] (0,4.5) -- ++(2,0) node[midway,above] {$\ell_1$};
 \draw[dim] (2,4.5) -- ++(2,0) node[midway,above] {$\ell_2$}; 
 \draw (0,4.25) -- ++(0,0.5);
 \draw (2,4.25) -- ++(0,0.5);
 \draw (4,4.25) -- ++(0,0.5);
% 
\end{tikzpicture} %
\end{center}
\end{document}
% ---- EOF: shi.tex ----
Attachments
06.png
06.png (16.07 KiB) Viewed 8176 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10334
Joined: Mon Mar 10, 2008 9:44 pm

TikZ: \foreach applied to rotated axes

Post by Stefan Kottwitz »

TikZ can rotate around any point, by adding the rotate around={<angle>:<coordinate>} option to \draw, \path or to a scope, for example. Like this:

Code: Select all

\begin{scope}[rotate around={45:(2,3)}] 
 ...
\end{scope}
So you just need to find point and angle. You can combine with xshift and yshift or shift.

Stefan
LaTeX.org admin
Sundial
Posts: 57
Joined: Thu Apr 19, 2012 7:28 pm

TikZ: \foreach applied to rotated axes

Post by Sundial »

So beautiful, Stefan! The att'd figure (upper side) is my first tentative to apply the highly suitable TikZ command you kindly suggested me, while the lower part shows what I wish to reach in the near future.
When I obtain some results, I hope to issue them (files .tex, I mean) with pleasure in this forum platform.
Thanks a lot and best wishes.
Attachments
78.png
78.png (67.71 KiB) Viewed 8169 times
Post Reply