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'd like to use TiKZ to generate stand-alone PDF diagrams programatically. I have an application that generates simple geometry of lines and arcs etc and I'd like to create (using e.g. Ruby) TikZ diagram text files from that simple geometry.

I have a bounding box (AABB) of each chunk of geometry and my question is what is the most idiomatic TiKZ and LaTeX/ConTeXt way of specifying what would in effect be a window-to-viewport transform between the application geometry bounds and the TiKZ drawing bounds?

I can see I can use:

\begin{tikzpicture}[x=2cm,y=1.5cm] 

to set distance units and:

scale=1.5 

parameter, but I suspect there's a better way.

Any advice is much appreciated,

share|improve this question
5  
Could you give a few more details? TikZ works out the bounding box as it goes along so it's not clear what you need to specify. Yes, you could get TikZ to change the distance units and the scale but then you could presumably also get the generating program to multiply all coordinates appropriately, so it's not clear to me what you need TikZ to do here. –  Andrew Stacey Aug 6 '12 at 9:40
    
Good point. I didn't make it clear that the geometry I want to draw is defined in its own "world" coordinate system, which changes from instance to instance. That's why I was looking for something like a world-to-viewport coordinates transform in TiKZ (which may not be a sensible use of TikZ). –  Stuart Hungerford Aug 6 '12 at 22:56
add comment

1 Answer

I'm not sure this is what your looking for, but probably you want something like this:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}

\begin{document}

\newcommand{\xangle}{10}
\newcommand{\yangle}{110}
\newcommand{\zangle}{45}

\newcommand{\xlength}{1}
\newcommand{\ylength}{1.7}
\newcommand{\zlength}{0.6}

\pgfmathsetmacro{\xx}{\xlength*cos(\xangle)}
\pgfmathsetmacro{\xy}{\xlength*sin(\xangle)}
\pgfmathsetmacro{\yx}{\ylength*cos(\yangle)}
\pgfmathsetmacro{\yy}{\ylength*sin(\yangle)}
\pgfmathsetmacro{\zx}{\zlength*cos(\zangle)}
\pgfmathsetmacro{\zy}{\zlength*sin(\zangle)}

\begin{tikzpicture}
[   x={(\xx cm,\xy cm)},
    y={(\yx cm,\yy cm)},
    z={(\zx cm,\zy cm)},
]
\draw[-latex,red] (-1,0,0) -- (3.5,0,0) node[label=\xangle:x] {};
\draw[-latex,blue] (0,-1,0) -- (0,3.5,0) node[label=\yangle:y] {};
\draw[-latex,black] (0,0,-1) -- (0,0,3.5) node[label=\zangle:z] {};

\foreach \c in {-1,...,3}
{   \fill[red] (\c,0,0) circle (0.05cm);
    \fill[blue] (0,\c,0) circle (0.05cm);
    \fill[black] (0,0,\c) circle (0.05cm);
}
\end{tikzpicture}

\end{document}

enter image description here

You can specify all axes as x={(x-component,y-component)}. In this example you can specify the angle in which a coordinate axis points (xangle) and it's length (xlength). From this, the components are automatically computed. In the options for the TikZ picture I wrote \xx cm, otherwise TikZ will assume the measures are given in points, thus resulting in a very tiny picture. Try playing around with the xyzangles and xyzlengths to see the picture change.

share|improve this answer
add comment

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.