Last week I made simple coordinate transformation in order to define \tdplotsetcoord
in Cartesian coord. system. My work and support of exp. user can be viewed in this topic. The code looks as follows:
\def\Sx{0} \def\Sy{0} \def\Sz{-3}
\tdplotsetcoord{S}{sqrt((\Sx)^(2) + (\Sy)^(2) + (\Sz)^(2))}{acos(\Sz/(sqrt((\Sx)^(2) + (\Sy)^(2) + (\Sz)^(2))))}{ifthenelse(\Sy<0,-acos(\Sx/(sqrt((\Sx)^(2) + (\Sy)^(2)))),acos(\Sx/(sqrt((\Sx)^(2) + (\Sy)^(2)))))} % {radius}{polar}{asimuth}
However there is a problem with (0,0,z)
Cartesian coordinates due to zero
division in those math expressions. Also I'm trying to define transformation from zero C. coordinates manually using ifthenelse
command:
1) Why variable = 0
doesn't work? I'm getting PGF Math Error: Unknown operator '=' or '=0'
. This is the example of polar angle
transformation:
\pgfmathsetmacro\polar{ifthenelse(\Sx=0 \AND \Sy=0 \AND \Sz=0,0,acos(\Sz/(sqrt(\Sx^(2) + \Sy^(2) + \Sz^(2)))))}
2) I failed also with \equal
command getting bunch of errors (log file). Can you show me the correct syntax? Thanks.
\pgfmathsetmacro\polar{ifthenelse(\equal{\Sx}{0} \AND \equal{\Sy}{0} \AND \equal{\Sz}{0},0,acos(\Sz/(sqrt(\Sx^(2) + \Sy^(2) + \Sz^(2)))))}
Edit: Working example does not differ from previous topic.
MWE:
\documentclass[a4paper,fleqn,leqno]{article}
\usepackage{tikz,tikz-3dplot}
\usetikzlibrary{arrows.meta,decorations.markings}
\begin{document}
\begin{tikzpicture}[cm={-1,-1,1,0,(0,0)},x=3.85mm,z=-1cm]
\draw[-{Classical TikZ Rightarrow[scale=1.2]},thick] (-2,0,0) -- (5,0,0) node[anchor=north,xshift=-3pt] {$x$};
\draw[-{Classical TikZ Rightarrow[scale=1.2]},thick] (0,-2,0) -- (0,5,0) node[anchor=west] {$y$};
\draw[-{Classical TikZ Rightarrow[scale=1.2]},thick] (0,0,-2) -- (0,0,5) node[anchor=south] {$z$};
\def\Sx{0} \def\Sy{0} \def\Sz{-3}
% code without dealing with zero division
\tdplotsetcoord{S}{sqrt((\Sx)^(2) + (\Sy)^(2) + (\Sz)^(2))}{acos(\Sz/(sqrt((\Sx)^(2) + (\Sy)^(2) + (\Sz)^(2))))}{ifthenelse(\Sy<0,-acos(\Sx/(sqrt((\Sx)^(2) + (\Sy)^(2)))),acos(\Sx/(sqrt((\Sx)^(2) + (\Sy)^(2)))))}
% code implementing zero coordinations definition
\pgfmathsetmacro\polar{ifthenelse(\Sx=0 \AND \Sy=0 \AND \Sz=0,0,acos(\Sz/(sqrt(\Sx^(2) + \Sy^(2) + \Sz^(2)))))}
% plus asimuth angle zero definition...
\tdplotsetcoord{S}{sqrt((\Sx)^(2) + (\Sy)^(2) + (\Sz)^(2))}{\polar}{...}
\draw[-{Stealth[scale=1.5,width=3pt]},color=red,thick] (0,0,0) -- (S) node[midway,anchor=east,font=\footnotesize] {${\vec{r}}_{1}$};
\draw[dashed,color=red!70!white,semithick] (0,0,0) -- (Sxy);
\draw[dashed,color=red!70!white,semithick] (Sxy) -- (S);
\end{tikzpicture}
\end{document}
ifthenelse
here should actually be\ifthenelse
from theifthen
package. It will be much easier to help if you construct a minimal working example (MWE) showing the issue. – Joseph Wright♦ Aug 9 '14 at 10:01pgf
'sifthenelse
keyword is for maths expressions only and uses&&
for logical 'and', while the syntax you seem to be using is for the\ifthenelse
macro from theifthen
package. Am I right in my understanding? – Joseph Wright♦ Aug 9 '14 at 11:38&&
there remains just single errorPGF Math Error: Unknown operator '=' or '=0'
when implementing\Sx=0 && \Sy=0 && \Sz=0
. Using\equal{\Sx}{0} && \equal{\Sy}{0} && \equal{\Sz}{0}
there are still too much errors... – user46581 Aug 9 '14 at 11:59