I can map a point (x,y) to polar coordinates (angle,length).
However, let's say in this (angle, length) pair, "length" doesn't actually interest me, so I can map (x,y) to a one dimensional coordinate space (angle). Given a bunch of points in this space, of course I lose some information and can't return to (x,y), but I don't care about that. I also don't care that in 1D space the component is an angle in the interval [-pi,pi] or [0,2pi], it just happens to be one when I convert 2D polar coordinates to 1D (angle) by discarding away the second component, but could be something different. If each angle in polar coordinates essentially defines a line segment or "ray" from the origin outward, I only care about the fact that only points on the same line segment or "ray" should map to the same point in that 1D coordinate space.
Given this bonus information, are there other ways to map (x,y) onto some 1D space?
The actual purpose here is the following: In software programming, I have to use inverse trigonometric functions to get the angle from the (x,y) pair. These are (relatively) slow (i.e. take a relatively long time to compute). I wonder if there's a mapping that can be computed with cheaper instructions.
Option 1. The usual
atan2maps a point $(x,y)$ to the point on the same ray which lies on the unit circle, which is then taken to be coordinatized by angle. You could replace the circle in this construction with, say, a diamond shape:and then coordinatize the diamond shape with numbers from $0$ to $4$. For example, if $(x,y)$ is in the first quadrant (as in the diagram), then the corresponding point on the diamond is $(\frac{x}{x+y},\frac{y}{x+y})$. If you want points on the positive $x$-semiaxis to have coordinate $0$ and points on the positive $y$-semiaxis to have coordinate $1$, you can take $\frac{y}{x+y}$ as the coordinate. Repeating this for the other three quadrants makes this function: $$ g(x,y) = \begin{cases} \frac{y}{x+y} &\text{if $x\ge 0$ and $y\ge 0$,} \\ 1-\frac{x}{y-x} &\text{if $x\le 0$ and $y\ge 0$,} \\ 2+\frac{y}{x+y} &\text{if $x\le 0$ and $y\le 0$,} \\ 3+\frac{x}{x-y} &\text{if $x\ge 0$ and $y\le 0$.} \end{cases} $$
Option 2. If all you need is to determine whether two given vectors lie on the same ray, you don't need to project-and-compare. You could use this criterion instead: points $(x_1,y_1)$ and $(x_2,y_2)$ lie on the same ray from the origin if and only if $$ x_1y_2 - x_2y_1 = 0 \quad\text{and}\quad x_1x_2 + y_1y_2 > 0 $$ The first condition ensures that the points lie on the same line through the origin and the second ensures they lie in the same halfplane. (This comes from geometric interpretations of the determinant and the dot product; alternatively, if you expand everything in polar coordinates and use the addition formulas for sin and cos, you'll find that these say the angle between the vectors is zero.) (Let me know if you want any details here.)