4

Consider an example like this drawing using a 3d perspective. The package tikz3d defines a new coordinate system 3d, and the coordinates are specified as (3d cs:1,2,3) etc.

Is is possible to set the coordinate system globally for the current scope in order to avoid the prefix 3d cs: in each coordinate? Is there something like every coordinate/.cs={3d}?

gernot
  • 49,614

1 Answers1

7

The coordinate specification (1,2,3) will eventually be processed by

\pgfpointxyz{1}{2}{3}

You can redefine this macro (locally) to implement a different coordinate system.

To be specific, \pgfpointxyz is a macro that reads three numbers and defines \pgf@x to be the desired x-coordinate and \pgf@y to be the desired y-coordinate. (See pgfcorepoints.code.tex line 852-864 for its original definition.)


In this case, where a coordinate system is well-prepared, you may also do

\def\tikz@parse@splitxyz#1#2#3,#4,{%
    \def\pgfutil@next{\tikz@scan@one@point#1(3d cs:{#2},{#3},{#4})}%
}

See tikz.code.tex line 5415-5417 for its original definition.


By the way, there is already a library called 3d, you probably want to use a different name other than 3d.


This is a working example. The code of the two tikzpicture are the same. But with different parsers they result in different curves.

\documentclass[border=9,tikz]{standalone}
\usetikzlibrary{3d}
\begin{document}

\makeatletter
\def\tikz@parse@splitxyz#1#2#3,#4,{%
    \def\pgfutil@next{\tikz@scan@one@point#1(xyz cylindrical cs:angle=#2,radius=#3,z=#4)}%
}
\tikz{
    \draw(0,2,0)foreach\i in{1,...,200}{
        --(17*\i,2,\i/80)
    };
}
\def\tikz@parse@splitxyz#1#2#3,#4,{%
    \def\pgfutil@next{\tikz@scan@one@point#1(xyz spherical cs:angle=#2,radius=#3,latitude=#4 r)}%
}
\tikz{
    \draw(0,2,0)foreach\i in{1,...,200}{
        --(17*\i,2,\i/80)
    };
}

Edit log: @Schrödinger's cat notices the changes of the internal macro name which invalidate my answer. So I correct it.

Symbol 1
  • 36,855
  • That's a nice answer which I had upvoted some time ago. According to what I find you need with the more recent versions of TikZ \def\pgfutil@next instead of \def\@next. –  Mar 19 '20 at 23:42