我们可以在球坐标中指定方向吗?
我知道我们可以做极坐标,(angle:radius)
但是我们正在使用什么tikz-3d
,并想指定(r, theta, phi)
方位角 theta 在哪里?
答案1
TikZ 通过明显未记录的库提供了3d
一个xyz spherical
坐标系统。
它接受键radius
(现在已修复)、angle
= longitude
,latitude
以及在我的帮助下rho
和theta
。
第一张 TikZ 图片显示了我的示例,第二张是 TikZ/PGF 手册的 PGF 图片示例。
(我3d
再次删除了库并实现了xyz spherical
与在中类似的功能tikzlibrary3d.code.tex
。它只是使用\pgfpointspherical
宏,宏完成所有计算并使用适当的向量。)
代码
\documentclass[tikz,convert=false]{standalone}
%\usetikzlibrary{3d}
\makeatletter
\pgfqkeys{/tikz/cs}{
latitude/.store in=\tikz@cs@latitude,% not needed with '3d' library
longitude/.style={angle={#1}},% not needed with '3d' library
theta/.style={latitude={#1}},
rho/.style={angle={#1}}
}
\tikzdeclarecoordinatesystem{xyz spherical}{% needed even with '3d' library!
\pgfqkeys{/tikz/cs}{angle=0,radius=0,latitude=0,#1}%
\pgfpointspherical{\tikz@cs@angle}{\tikz@cs@latitude}{\tikz@cs@xradius}% fix \tikz@cs@radius to \tikz@cs@xradius
}
\makeatother
\tikzset{my color/.code=\pgfmathparse{(#1+90)/180*100}\pgfkeysalso{every path/.style={color=red!\pgfmathresult!blue}}}
\begin{document}
\begin{tikzpicture}[radius=+0.4pt]% (this is the radius of little dots on the lines)
\foreach \lat in {-90,-80,...,90} {
\tikzset{my color=\lat}
\foreach \lon in {0,10,...,359} {
\filldraw (xyz spherical cs: radius=1, angle=\lon, latitude=\lat) circle[]
-- (xyz spherical cs: radius=1, angle=\lon+10, latitude=\lat);
}}
\end{tikzpicture}
\begin{tikzpicture}
\foreach \lat in {-90,-75,...,30}
\filldraw[line join=round, fill=lightgray]
\foreach \lon in {0,20,...,359} {
(xyz spherical cs: radius=1, rho=\lon, theta=\lat )
-- (xyz spherical cs: radius=1, rho=\lon+20, theta=\lat )
-- (xyz spherical cs: radius=1, rho=\lon+20, theta=\lat+15)
-- (xyz spherical cs: radius=1, rho=\lon, theta=\lat+15)
-- cycle
};
\end{tikzpicture}
\end{document}
输出
答案2
我相信这是一个有趣的问题。
首先,我想指出的是,物理学家的符号与数学家的符号不同。物理学家所称的西塔(ϴ),数学家称之为披(φ)反之亦然。我建议读者参阅维基百科网站 针对所使用的惯例。宏很简单,我将它与此处要求的惯例一起包含在内。
\newcommand{\sphToCart}[3]
{
\def\rpar{#1}
\def\thetapar{#2}
\def\phipar{#3}
\pgfmathsetmacro{\x}{\rpar*sin(\phipar)*cos(\thetapar)}
\pgfmathsetmacro{\y}{\rpar*sin(\phipar)*sin(\thetapar)}
\pgfmathsetmacro{\z}{\rpar*cos(\phipar)}
}
这是一个完整的例子,我们多次使用这个宏来创建一个球面三角形。
\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usepackage{tkz-berge}
\usepackage{tikz-3dplot}
\usetikzlibrary{calc,3d,decorations.markings, backgrounds, positioning,intersections,shapes}
\newcommand{\sphToCart}[3]
{
\def\rpar{#1}
\def\thetapar{#2}
\def\phipar{#3}
\pgfmathsetmacro{\x}{\rpar*sin(\phipar)*cos(\thetapar)}
\pgfmathsetmacro{\y}{\rpar*sin(\phipar)*sin(\thetapar)}
\pgfmathsetmacro{\z}{\rpar*cos(\phipar)}
}
\begin{document}
\begin{tikzpicture}[scale=1.3]
\coordinate (O) at (0,0,0);
\tdplotsetmaincoords{60}{135}
\pgfmathsetmacro\R{sqrt(3)}
\fill[ball color=white!10, opacity=0.2, name path global=C] (O)
circle (\R); % 3D lighting effect
\begin{scope}[tdplot_main_coords, shift={(0,0)}]
\pgfmathsetmacro\R{sqrt(3)}
\pgfmathsetmacro{\thetavec}{0};
\pgfmathsetmacro{\phivec}{0};
\pgfmathsetmacro{\gammav}{0};
\tdplotsetrotatedcoords{\phivec}{\thetavec}{\gammav};
% draw point with azimuth -20 degrees, polar angle 90
\def\thetaA{-20}
\def\phiA{90}
\sphToCart{\R}{\thetaA}{\phiA}
\coordinate (A) at (\x,\y,\z);
% save legend location
\pgfmathsetmacro{\dx}{\x+1.2};
\pgfmathsetmacro{\dy}{\y+0.9};
\pgfmathsetmacro{\dz}{\z-1.0};
\node[] at (\dx,\dy,\dz) {Point $A:( r=\R, \theta=\thetaA, \phi=\phiA)$};
\node[yshift=-5mm, xshift=6mm] at (\dx,\dy,\dz)
{ $( x=\x, y=\y, z=\z)$};
\def\thetaA{110}
\def\phiA{90}
\sphToCart{\R}{\thetaA}{\phiA}
\coordinate (B) at (\x,\y,\z);
% save legend location (relative to this point)
\pgfmathsetmacro{\dx}{\x-1.2};
\pgfmathsetmacro{\dy}{\y+2.5};
\pgfmathsetmacro{\dz}{\z-1.0};
\node[] at (\dx,\dy,\dz) {Point $B:( r=\R, \theta=\thetaA, \phi=\phiA)$};
\node[yshift=-5mm, xshift=6mm] at (\dx,\dy,\dz)
{ $( x=\x, y=\y, z=\z)$};
\def\thetaA{70}
\def\phiA{-20}
\sphToCart{\R}{\thetaA}{\phiA}
\coordinate (C) at (\x,\y,\z);
% save legend location (relative to this point)
\pgfmathsetmacro{\dx}{\x-2};
\pgfmathsetmacro{\dy}{\y+3};
\pgfmathsetmacro{\dz}{\z+1.0};
\node[] at (\dx,\dy,\dz) {Point $C:( r=\R, \theta=\thetaA, \phi=\phiA)$};
\node[yshift=-5mm, xshift=6mm] at (\dx,\dy,\dz)
{ $( x=\x, y=\y, z=\z)$};
\draw[fill=red, opacity=0.4] (A) to [bend right] (B)
to [bend right] (C) to [bend right] (A);
\draw[-latex, color=red, line width=1] (O)--(A) node[anchor=east] {\tiny $A$};
\draw[-latex, color=red, line width=1] (O)--(B) node[anchor=west] {\tiny $B$};
\draw[-latex, color=red, line width=1] (O)--(C) node[anchor=south] {\tiny $C$};
%legend
% axis
\coordinate (XX) at (3,0,0) ;
\coordinate (YY) at (0,3,0) ;
\coordinate (ZZ) at (0,0,3) ;
\draw[-latex] (O) -- (XX) node[anchor=east] {$X$};
\draw[-latex] (O) -- (YY) node[anchor=north] {$Y$};
\draw[-latex] (O) -- (ZZ) node[anchor=south] {$Z$};
\end{scope}
\end{tikzpicture}
\end{document}
如下图:
请注意,我包含了显示两个系统(球面坐标和笛卡尔坐标)的坐标的图例。