Alternatives to polar coordinates for mapping point onto one dimensional coordinate

1k Views Asked by At

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.

3

There are 3 best solutions below

0
On BEST ANSWER

Option 1. The usual atan2 maps 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:

enter image description here

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.)

1
On

Maybe I don't fully understand your question, but what is wrong with using the standard mapping $z = x + iy \mapsto \arg(z)$?

You could also embed this in any invertible function, like $z \mapsto e^{\arg(z)}$, or $z \mapsto m \arg(z) + b$. This will still allow you to recover the original angle/ray.

EDIT

To achieve your goal you might also try the following: $$ x + iy \mapsto q + e^{-|y/x|} $$ where $q$ is the quadrant that $(x,y)$ lies in ($1,2,3,$ or $4$). Given such a number, the integer part is the quadrant and the fractional/decimal part is $e^{-|y/x|}$ from which you can recover the absolute value of the slope of the ray. This is enough to get the angle you wish. I don't really know if it is computationally faster than using $\arg(z)$ though.

0
On

Here's an idea:

It seems that what you really want to do is make a function $f(x,y)$ such that $f(x,y) = f(x',y')$ if and only if $(x,y)$ and $(x',y')$ lie on the same ray emerging from the origin.

To that end, we can use something like the traditional $\arctan(y/x)$, but replacing $\arctan(z)$ with some $g(z)$ that is monotonically increasing between two horizontal asymptotes.

To that end, you could use something like $g(z) = \frac{z}{1+|z|}$. If you want to make this like "atan2" in that it distinguishes between colinear rays, you could come up with an assignment such as $$ f(x,y) = \begin{cases} g(y/x) & y \geq 0,x\neq 0\\ 1 & y > 0,x = 0\\ g(y/x) + 2 & y < 0, x \neq 0\\ 3 & y < 0, x = 0\\ 0 & x,y=0 \end{cases} $$ In this way, $f$ maps each angle to a unique point on $[-1,3]$. That should give you a good starting point.