cartesian_polar_spehrical.txt (3579B)
1 Cartesian (x, y), polar (r, θ), spherical (r, θ, φ) 2 3 Coordinate systems: different ways of naming the same point in space. 4 The point never moves; only the labels change. Pick the system whose 5 symmetry matches the problem's symmetry. 6 7 8 CARTESIAN (x, y) in 2D, (x, y, z) in 3D 9 ---------------------------------------- 10 Signed distances along fixed perpendicular axes. 11 12 - Every coordinate is a length, all axes are interchangeable. 13 - Unique: one point <-> exactly one tuple. 14 - Translation is addition; rotation needs a matrix. 15 - Straight lines and boxes are trivial; circles and spheres are not 16 (x^2 + y^2 = r^2 has a square root in it). 17 18 Use when: grids, pixels, arrays, linear algebra, anything axis-aligned. 19 20 21 POLAR (r, θ) -- 2D 22 -------------------- 23 Distance from origin + angle from the +x axis. 24 25 r >= 0 radius 26 θ angle, CCW from +x axis, typically (-π, π] or [0, 2π) 27 28 x = r cos θ r = sqrt(x^2 + y^2) 29 y = r sin θ θ = atan2(y, x) <- atan2, never atan(y/x) 30 31 - NOT unique: θ is mod 2π, and r = 0 leaves θ undefined (the origin is 32 a singularity). (r, θ) and (r, θ + 2π) are the same point. 33 - Circles become r = const: one coordinate instead of an equation. 34 - Rotation is addition on θ; scaling is multiplication on r. 35 - Area element is r dr dθ, not dr dθ -- the Jacobian matters. 36 37 Use when: rotation, orbits, radar/lidar returns, wave propagation, 38 anything radially symmetric about a point. 39 40 Cylindrical (r, θ, z) is polar with an untouched z bolted on -- use for 41 things symmetric about an axis (pipes, wheels, extrusions). 42 43 44 SPHERICAL (r, θ, φ) -- 3D 45 --------------------------- 46 Distance from origin + two angles. 47 48 WARNING: conventions collide. Two common ones: 49 50 ISO / physics: θ = polar angle from +z axis [0, π] 51 φ = azimuth in xy-plane [0, 2π) 52 x = r sin θ cos φ 53 y = r sin θ sin φ 54 z = r cos θ 55 r = sqrt(x^2+y^2+z^2), θ = acos(z/r), φ = atan2(y, x) 56 57 Math / US calc: θ and φ are swapped. 58 59 Geography uses latitude (measured from the equator, not the pole) and 60 longitude, so lat = 90° - θ_ISO. Always check which one a library means. 61 62 - Singular at r = 0 (both angles undefined) and at the poles 63 (φ undefined when θ = 0 or π). This is gimbal lock's cousin -- it's 64 why orientation is stored as quaternions, not Euler angles. 65 - Volume element is r^2 sin θ dr dθ dφ. 66 67 Use when: point sources, gravity/EM fields, globes, ray directions, 68 camera look-at angles, spherical harmonics. 69 70 71 COMPARISON 72 ---------- 73 Cartesian Polar / Spherical 74 coordinates all lengths one length + angles 75 uniqueness unique not unique (mod 2π; poles degenerate) 76 origin nothing special singular 77 translation cheap (add) expensive (round-trip to Cartesian) 78 rotation matrix multiply cheap (add to angle) 79 distance Pythagoras law of cosines / haversine 80 natural shape boxes, lines circles, spheres, cones 81 interpolation straight lines arcs (and θ must wrap correctly!) 82 83 Practical notes: 84 - Convert to Cartesian to add vectors; convert back to read off angles. 85 - Interpolating angles naively goes the wrong way around at the ±π 86 seam. Use the shortest signed difference: atan2(sin d, cos d). 87 - Comparing radii? Compare r^2 and skip the sqrt. 88 - Great-circle distance on a sphere is r * central angle; use the 89 haversine form, since acos of a dot product loses precision for 90 nearby points.