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 noticed that for values close to 0° and 180° the angular values dramatically changes if the values are imported from cartesian data. Here the code (with cartesian coordinates plotted in polar with data cs=cart and the same coordinates in polar coordinates obtained with arctan2 Matlab function) and illustration:

\documentclass{minimal}
\usepackage{eurosym}
\usepackage{pgfplots}
\usepackage{fp}

\begin{document}

\pgfplotsset{compat=newest} 
\usepgfplotslibrary{polar}
\centering
\begin{tikzpicture}
\begin{polaraxis}[
    visualization depends on=x \as \pgfplotspointx,
    nodes near coords,
    every node near coord/.style={
        %font=\small,
        rotate=\pgfplotspointx,
        append after command={
            node [
                anchor=south,
                %font=\small,
                rotate=\pgfplotspointx,
                shift={(axis direction cs:0,(12.75-\pgfplotspointmeta))}
            ] {$\pgfmathprintnumber{\pgfplotspointx}^\circ$}
        }
    },
width=7\textwidth,
xmin=-2,xmax=1, ymin=12, ymax=16,
title=artctan2 precision problem,
grid=both,
minor x tick num={4}, 
minor y tick num={1},
]
\addplot+[polar comb, data cs=cart, mark size=1, mark=asterisk, color=blue, dashed] table {
14.370195   -0.304948
14.370195   -0.304948

}; 
\addplot+[polar comb, mark size=1, mark=asterisk, color=green, solid] table {-1.215683667   14.37343027
-1.215683667    14.37343027
}; 
\end{polaraxis}
\end{tikzpicture}


\end{document}

enter image description here

Has anyone meet this issue?

Thank you in advance.

share|improve this question
    
Yes this is known and there is not much you can do about it. –  percusse Aug 6 at 13:49
    
@percusse: Hm, but \pgfmathparse{atan2(14.37,-0.304948)} \pgfmathresult gives the (almost) correct result of -1.20. Maybe there's something else at play in the conversion from cartesian to polar coordinates in PGFPlots? –  Jake Aug 6 at 13:52
    
@Jake The conversion doesn't use it I think. I had a similar problem before and I guess we need to dive into polar code. Maybe I should say not much without hacking into the code. I think somewhere in the drawing fpu is turned off. –  percusse Aug 6 at 13:57
    
Thank you for your fast comments. Thus, I will directly manipulate polar coordinates instead of using data cs =cart. –  Willi Aug 6 at 14:30

2 Answers 2

up vote 4 down vote accepted

This needs to be repaired in pgfplots, I accept this question as bug report.


Details:

The routine pgfplotsmathcarttopol does not make use of atan2 - instead, it computes the angle "manually", apparently with less precision.

add

\pgfplotsmathcarttopol{14.370195}{-0.304948}\angle\radius

angle = \angle; radius = \radius

to see that this is, indeed, the root cause.

Steps to be done would be to write an implementation (or adapter) for atan2 for the floating point unit of PGF and to use that one in pgfplotsmathcarttopol.

I will take a note for the todo list of pgfplots (no need to file a separate bug report).

share|improve this answer
    
OK. Thank you for your fast answer. I leave it like this (no bug report). –  Willi Aug 6 at 14:33

A solution with PSTricks. Run it with xelatex:

\documentclass{minimal}
\usepackage{pst-plot}
\begin{document}

\begin{pspicture}(33,-2)(48,1.1)
\psset{runit=3}\uput[0](16;0){0}
\psarcn(0,0){12}{1}{-2}\psarcn(0,0){16}{1}{-2}
\psline(12;1)(16;1)\psline(12;-2)(16;-2)
\multido{\rA=12.25+0.25}{15}{\psarcn[linecolor=black!15](0,0){\rA}{1}{-2}}
\psline[linecolor=black!15](12;0)(16;0)\psline[linecolor=black!15](12;-1)(16;-1)
\multido{\rA=12.0+0.5}{9}{\uput[-90](\rA;-2.5){\rA}}
\psline[linecolor=blue,linestyle=dashed]{-*}(12;-0.54)(14.37;-0.54)
\psline[linecolor=green]{-*}(12;-1.22)(14.37;-1.22)
\uput[90](12.75;-0.54){\blue$-0.54^\circ$}\uput[90](12.75;-1.22){\green$-1.22^\circ$}
\uput[90](14.37;-0.54){\blue$14.37$}\uput[90](14.37;-1.22){\green$14.37$}
\end{pspicture}

\end{document}

enter image description here

share|improve this answer
    
Thank you for your answer! It seems to be a complete different package no? I am actually a new user of pgfplots so maybe I don't got all the tricks now! I will study your approach ;-) –  Willi Aug 6 at 19:49
    
Yes, it does all calculations with PostScript, a complete programming language. –  Herbert Aug 6 at 19:51

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.