From Cartesian to polar (从笛卡尔坐标到极坐标)
This document provides a simple introduction to converting Cartesian coordinates to polar coordinates. The conversion involves calculating the distance from the origin using the Pythagorean theorem and determining the angle using the arctangent function with appropriate quadrant adjustments. Key topics include the fundamental conversion formulas, handling special cases at coordinate axes, and practical implementation using the atan2 function in programming languages. Examples demonstrate the conversion process for points in different quadrants.
本文档提供了从笛卡尔坐标转换为极坐标的简单介绍。转换过程包括使用勾股定理计算到原点的距离,以及使用反正切函数并进行适当的象限调整来确定角度。主要内容包括基本转换公式、处理坐标轴上的特殊情况,以及在编程语言中使用atan2函数的实际实现。示例演示了不同象限中点的转换过程。
Converting Formula
Converting from Cartesian coordinates (x, y) to polar coordinates (r, θ) involves finding the distance from the origin and the angle from the positive x-axis. Given a point with Cartesian coordinates (x, y), the polar coordinates (r, θ) are:
Distance (radius):\[ r = \sqrt{x^2 + y^2}\]
Angle (in radians):\[ \theta = \arctan\left(\frac{y}{x}\right)\]
The basic arctan formula only gives angles in the range (-π/2, π/2). To get the correct angle in all quadrants:
- Quadrant I \((x > 0, y > 0)\): \(\theta = \arctan\left(\frac{y}{x}\right)\)
- Quadrant II \((x < 0, y > 0)\): \(\theta = \arctan\left(\frac{y}{x}\right) + \pi\)
- Quadrant III \((x < 0, y < 0)\): \(\theta = \arctan\left(\frac{y}{x}\right) + \pi\)
- Quadrant IV \((x > 0, y < 0)\): \(\theta = \arctan\left(\frac{y}{x}\right) + 2\pi\)
Special Cases:
- If \(x = 0\) and \(y > 0\): \(\theta = \frac{\pi}{2}\)
- If \(x = 0\) and \(y < 0\): \(\theta = \frac{3\pi}{2}\)
- If \(x = 0\) and \(y = 0\): \(\theta\) is undefined (origin)
Examples
Convert (3, 4) to polar coordinates:
- \(r = \sqrt{3^2 + 4^2} = \sqrt{25} = 5\)
- \(\theta = \arctan\left(\frac{4}{3}\right) \approx 0.927 \text{ radians} \approx 53.13°\)
Convert (-2, 2) to polar coordinates:
- \(r = \sqrt{(-2)^2 + 2^2} = \sqrt{8} = 2\sqrt{2}\)
- \(\theta = \arctan\left(\frac{2}{-2}\right) + \pi = \arctan(-1) + \pi = \frac{3\pi}{4} \text{ radians} = 135°\)
In programming languages
Many programming languages provide the `atan2(y, x)` function which automatically handles quadrant determination:
\[ \theta = \text{atan2}(y, x)\]This function returns angles in the range \((-\pi, \pi]\) and correctly accounts for the signs of both x and y.
To get the angle in \([0,2\pi)\), use additionally (in Python, use `np.mod`)\[ \theta = \text{mod}(\theta,\pi).\]