8

I would like to draw a curvilinear grid/mesh like this (sorry for freehand drawing) curvilinear grid

I thought the easiest (and most elegant) solution would be to apply a canvas transformation to a regular grid in TikZ.

However, I found only this example in the pgf/TikZ manual, which rotates a grid:

\documentclass{standalone}
\usepackage{pgf}
  \begin{document}
    \begin{pgfpicture}
    \pgftransformrotate{10}
    \pgfpathgrid[stepx=1mm,stepy=2mm]{\pgfpoint{0mm}{0mm}}{\pgfpoint{30mm}{30mm}}
    \pgfusepath{stroke}
  \end{pgfpicture}
\end{document}

rotated grid

Do these kind of transformations exist or should I use the recommended solution in this question on polar grids.

Sebastian
  • 1,766
  • 2
    To my (limited) knowledge, the only transformations that are possible internally are affine and therefore not able to do what you want. As evidence, note that the transformations act on the coordinates and not on the actual paths themselves, so a line stays a line whereas you want that line to transform to an arc. So my thinking is that the polar grid question will be your best bet. – Andrew Stacey Feb 10 '12 at 08:22

1 Answers1

10

Not exactly an answer because I think it's more complicated to transform a tool than to create a new tool. Like Andrew says it's impossible in your case.

Here a macro : ( I made this code in few minutes also I think tikz's expert can do a better macro with more options)

\documentclass{article}
\usepackage{fullpage,tikz} 
\makeatletter  
\pgfkeys{%
/polargrid/.cd,
rmin/.code ={\global\def\rmin {#1}},
rmax/.code ={\global\def\rmax {#1}},
amin/.code ={\global\def\amin {#1}},
amax/.code ={\global\def\amax {#1}},
rstep/.code={\global\def\rstep{#1}}, 
astep/.code={\global\def\astep{#1}}}

\def\polargrid{\pgfutil@ifnextchar[{\polar@grid}{\polar@grid[]}}%
\def\polar@grid[#1]{%
\pgfkeys{/polargrid/.cd,
rmin ={0},
rmax ={10},
amin ={0},
amax ={180},
rstep={1}, 
astep={10}}   
%
\pgfqkeys{/polargrid}{#1}%
\pgfmathsetmacro{\addastep}{\amin+\astep} 
\pgfmathsetmacro{\addrstep}{\rmin+\rstep} 
 \foreach \a in {\amin,\addastep,...,\amax}  \draw[gray] (\a:\rmin) -- (\a:\rmax);  
 \foreach \r in {\rmin,\addrstep,...,\rmax}  \draw[gray] (\amin:\r cm) arc (\amin:\amax:\r cm);    
 } 
\makeatother   
\begin{document} 

\begin{tikzpicture}[scale=.75] 
\polargrid
\end{tikzpicture}  

\begin{tikzpicture}[scale=.75] 
\polargrid[rmin=4,rmax=8,amin=20,amax=120]
\end{tikzpicture}  
\end{document} 

enter image description here

Alain Matthes
  • 95,075