极角的定义
如图所示,极坐标系中,每一个点M,都可以用其距离原点O的距离ρ\rhoρ和OM与x轴的夹角θ\thetaθ唯一确定。M的极坐标为(ρ,θ)(\rho,\theta)(ρ,θ),其中θ\thetaθ为极角。
极角的计算
设M点在直角坐标系中的坐标为(x,y)(x,y)(x,y),原点O的坐标为(0,0)(0,0)(0,0),则与极坐标存在如下等式关系:
{ρ=x2+y2tan(θ)=yx(x≠0)\begin{cases} \rho = x^2 + y ^ 2 \\ \tan(\theta) = \frac y x (x \neq 0)\end{cases}{ρ=x2+y2tan(θ)=xy(x=0)或{x=ρcos(θ)y=ρsin(θ)\begin{cases} x = \rho \cos(\theta) \\ y = \rho \sin(\theta) \end{cases}{x=ρcos(θ)y=ρsin(θ)
所以,极角θ=arctan(yx)\theta=\arctan(\frac y x)θ=arctan(xy)
代码实现
使用java.lang.Math的atan2函数,对于点M(x,y)(x,y)(x,y),其与原点O(0,0)(0,0)(0,0)的极角θ=Math.atan2(y,x)\theta = Math.atan2(y, x)θ=Math.atan2(y,x)
public static double atan2(double y, double x)
如果O的坐标为(x0,y0)(x_0,y_0)(x0,y0),点M(x,y)(x,y)(x,y)与O的极角为θ=Math.atan2(y−y0,x−x0)\theta = Math.atan2(y-y_0, x-x_0)θ=Math.atan2(y−y0,x−x0)