Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 1x 1x 1x 18x 18x 18x 18x 18x | import { type Cartesian, type Polar } from './@types/geometry.ts'; import { type UnitOptions } from './angle.ts'; import { normalizeAngle } from './normalize-angle.ts'; import { toAngle } from './to-angle.ts'; /** * Convert cartesian coordinates to polar * @param coordinate - The Cartesian coordinate to convert. * @param options - see {@link UnitOptions} * @returns polar coordinated * @group Geometry * @category Coordinates */ export function toPolar(coordinate: Cartesian, { unit = 'radians' }: UnitOptions = {}): Polar { return { r: Math.hypot(coordinate.x, coordinate.y), φ: toAngle(normalizeAngle(Math.atan2(coordinate.y, coordinate.x)), 'radians', unit), }; } |