TIKZ的计算宏包算直线与圆交点坐标不精确?

发布于 2026-03-01 15:35:17

在用TIKZ内intersections,calc宏包计算与X轴成150度、225度特殊角直线与圆的交点后,输出显示这些点的直角坐标、极坐标值时,发现有数值上的误差,用三角函数公式计算验证时就不是这些数值,这现象是如何引起的呢?

image.png

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections, calc}
\begin{document}
\def\pttocm#1{\pgfmathparse{#1/28.45274}\pgfmathresult}
\makeatletter
\def\b{8}    
\def\a{tan(225)}    
\def\c{tan(150)}        
\begin{tikzpicture}
\draw[->](-10,0) -- (10,0) node[right] {$x$};
\draw[->](0,-10) -- (0,10) node[left] {$y$};
\draw[name path global=m,black,line width=0.5pt,domain=0*pi:2*pi,samples=360] plot({\b*sin(\x r)},{\b*cos(\x r)});
\draw[name path global=n,black,line width=0.5pt,domain=0:-8,samples=10] plot(\x,{\a*\x});    
\draw [name intersections={of=n and m, by=u}][teal,fill=orange](u) circle(5pt);     
\draw[name path global=k,black,line width=0.5pt,domain=0:-8,samples=5] plot(\x,{\c*\x});    
\draw [name intersections={of=k and m, by=s}][teal,fill=orange](s) circle(5pt);     
\pgfpointanchor{u}{center}
\pgfgetlastxy{\ux}{\uy}
\pgfpointanchor{s}{center}
\pgfgetlastxy{\sx}{\sy}
\fill[purple,font=\Large] let \p1=(u) in (\p1) circle (2pt) node  at(-3,-5) {$[x=\pttocm{\the\pgf@x}]$};
\fill[purple,font=\Large] let \p1=(u) in (\p1) circle (2pt) node  at(-3,-5.75) {$[y=\pttocm{\the\pgf@y}]$};
\fill[purple,font=\Large] let \p1=(s) in (\p1) circle (2pt) node  at(-3,5.75) {$[x=\pttocm{\the\pgf@x}]$};
\fill[purple,font=\Large] let \p1=(s) in (\p1) circle (2pt) node  at(-3,5) {$[y=\pttocm{\the\pgf@y}]$};
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\coordinate (A) at (0,0);
\coordinate (B) at (\ux,\uy);
\coordinate (C) at (\sx,\sy);
\pgfmathanglebetweenpoints{\pgfpointanchor{A}{center}}{\pgfpointanchor{B}{center}}
\edef\angle{\pgfmathresult}
\node at (-5.5,-6.75) [blue,font=\Large] {$[\rho=\b]$};
\node at (-4.5,-7.5) [blue,font=\Large] {$[\theta=\angle^\circ]$};
\pgfmathanglebetweenpoints{\pgfpointanchor{A}{center}}{\pgfpointanchor{C}{center}}
\edef\angle{\pgfmathresult}
\node at (-1.5,4.25) [blue,font=\Large] {$[\rho=\b]$};
\node at (-0.5,3.5) [blue,font=\Large] {$[\theta=\angle^\circ]$};
\end{tikzpicture}
\end{document}        

abc.jpg
document_test2.tex

查看更多

关注者
0
被浏览
51
1 个回答
Sagittarius Rover
Sagittarius Rover 8小时前
这家伙很懒,什么也没写!

也许是精度误差(?)

\documentclass[tikz]{standalone}
\begin{document}
    \begin{tikzpicture}
        \node {\fpeval{tand(45)} v.s. \pgfmathparse{tan(45)}\pgfmathresult};
    \end{tikzpicture}
\end{document}        

image.png

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览