已知平面直角坐标系上点 (a,b)(a,b)(a,b) ,有弧度制极角 θ\thetaθ ,求过 (a,b)(a,b)(a,b) ,与 xxx 轴夹角为 θ\thetaθ 的直线与 xxx 轴的交点。
方法一:
情况1: θ<π2\theta<\frac{\pi}{2}θ<2π
此时 cot θ=xb,x=b×cot θcot\ \theta=\frac{x}{b},x=b\times cot\ \thetacot θ=bx,x=b×cot θ ,交点= a−x=a−b×cot θa-x=a-b\times cot\ \thetaa−x=a−b×cot θ 。
情况2: θ>=π2\theta>=\frac{\pi}{2}θ>=2π
此时 α=π−θ,cot α=xb,x=b×cot α=b×cot (π−θ)\alpha=\pi-\theta,cot\ \alpha=\frac{x}{b},x=b\times cot\ \alpha=b\times cot\ (\pi-\theta)α=π−θ,cot α=bx,x=b×cot α=b×cot (π−θ) 。
交点 =a+x=a+b×cot (π−θ)=a+x=a+b\times cot\ (\pi-\theta)=a+x=a+b×cot (π−θ) 。
因为 C++
没有 cotcotcot 函数,所以要用 cot θ=1tan θcot\ \theta=\frac{1}{tan\ \theta}cot θ=tan θ1 来计算。
方法二:
情况1、情况2如上图。
情况1中 tan θ=bxtan\ \theta=\frac{b}{x}tan θ=xb ,也就是该直线的斜率,利用斜率求出交点。
情况二则是 tan (π−θ)tan\ (\pi-\theta)tan (π−θ) 。