how covert joysitck (x, y) coordinates to robot motor speed? I am trying to formulate an equation to calculate left and right motor speeds of a robot. The robot is four wheeled drive with independent motors connected to tank-like best on each side. 
see this https://www.sparkfun.com/products/10336 So, the robot can be controlled using left and right speeds. Lets assume the left and right speeds, VL and VR are in range [-1, 1].
The joystick gives (x, y) position. Lets assume x and y are in range [-1, 1]. y value controls forward/backward movement and x value controls the turn.
Here is the desired behaviour (boundary conditions).(On left is the (x, y) joystick position, on right is the velocity (VL, VR))
Stop position


*

*(0, 0) --> (0, 0)


Go Forward


*

*(0, 1) --> (1, 1)


Turn right (clockwise)


*

*(1, 0) --> (1, -1)


Go Forward while turning right


*

*(1, 1) --> (1, 0)


Similar behaviour in other three quadrants as well (for moving back, turning left etc)
I want to have a smooth function of (x, y) which return (VL, VR) satisfying this conditions and have smooth transitions. (Hopefully it should closely resemble driving a car in a game)
How should I go about deriving such a function? Multivariate interpolation?
 A: One idea is to use the similarity with polar coordinates in the transformation you want. The idea relies on the fact that you need to split the transformation in four cases, one for each of the quadrants of the joystick position. I will do the first quadrant ($x \ge 0, y \ge 0$), and then it's easy to apply the same concept to the other quadrants.
The first quadrant is the home of the coordinates $(0,0), (0,1), (1,0)$ and $(1,1)$, and they have the corresponding motor velocities $(0,0), (1,1), (1,-1)$ and $(1,0)$ respectively. Denote the joystick position $(x,y)$ and the motor velocities $(\alpha,\beta)$. See the below picture of the first quadrant, where the desired $(\alpha,\beta)$ velocities are written in the $(x,y)$ coordinate system. 

Now, if the $(x,y)$ was actually a circular area instead of a square, $\alpha$ would be the radius of $(x,y)$ and $\beta$ would be related to the angle of the $(x,y)$ vector relative to the x-axis. Let's assume a circle for now and correct for it later. As noted, $\alpha$ corresponds to the radius:
$$\alpha = \sqrt{x^2+y^2}$$
We want that the angle $\varphi = 0$ should give $\beta = -1$ and $\varphi = \frac{\pi}2$ should result in $\beta = 1$. Hence,
$$\beta = \sin\left(2\varphi - \frac{\pi}2\right)$$
But $\varphi = \arctan\frac{y}{x}$, so the expression simplifies to 
$$\beta = \frac{y^2-x^2}{y^2+x^2}$$
Now we have a way to transform $(x,y)$ to $(\alpha,\beta)$, but we need to scale $\alpha$ to account for the fact that it is a square area that we are transforming, and not a circular one. For example, with the current formulas, $(1,1) \rightarrow (\sqrt2,0)$, where $\alpha$ needs to be scaled by $\frac1{\sqrt2}$. 
Generally, the point $A$ in the below picture needs to be moved to $B$. 

The scaling factor for $\alpha$ can then be expressed as follows
$$\begin{cases}
s = \cos\varphi & 0 \le \varphi < \frac{\pi}4 \\
s = \cos\left(\frac{\pi}2-\varphi\right) & \frac{\pi}4 \le \varphi \le \frac{\pi}2 \\
\end{cases}$$
This simplifies to 
$$\begin{cases}
s = \frac{x}{\sqrt{x^2+y^2}} & 0 \le \varphi < \frac{\pi}4 \\
s = \frac{y}{\sqrt{x^2+y^2}} & \frac{\pi}4 \le \varphi \le \frac{\pi}2 \\
\end{cases}$$
Now, the final simplified transformation becomes:
$$\begin{cases}
\alpha = x\;, & 0 \le \arctan\frac{y}{x} < \frac{\pi}4 \\
\alpha = y\;, & \frac{\pi}4 \le \arctan\frac{y}{x} \le \frac{\pi}2 \\
\end{cases}\\
\beta = \frac{y^2-x^2}{y^2+x^2}$$
I realize now that this was an awful lot of writing to get to very simple expressions for $\alpha$, but having written all of this, I'll let i stand. 
Now, the same reasoning can be made in the other three quadrants, where it's just a matter of identifying which of the $\alpha$ or $\beta$ that should take the "radius" and "angle" part, and to decide on the sign. 
A: Here is a better polar route.
In my case, the joystick x axis ranged from [-127, 127].
The y-axis also had the same range.
First, I found the angle created between the x-axis and the vector (created when the joystick is pushed in a direction).
Then, I said the magnitude (speed) was how far out the joystick was pushed from the origin, which is the length of the vector from the origin.
$\theta$ = $atan2(y, x)$ returns the angle between a vector and the x-axis by being able to compute the arctangent of all four quadrants.
Let $magnitude$ = $\sqrt(x^2 +y^2)$ which returns the magnitude or the length of the vector from the origin.
Then, convert these polar coordinates to cartesian coordinates.
Let $x$ = $magnitude ⋅ cos(\theta)$
Let $y$ = $magnitude ⋅ sin(\theta)$
Then, scale these cartesian coordinates to motor power. In my case, motor power was between [-100, 100]. Negative values made the motor turn the opposite direction. Change for your scenario.
$x_1$ = $(100 ⋅ x)/127$ and 
$y_1$ = $(100 ⋅ y)/127$
Now set motor powers. $rightMotors$ = $-x_1$ and $leftMotors$ = $y_1$. The negative $x_1$ is because you need to be able to turn.
Just change some values and adopt this approach and it should work.
-Neehar Polavarapu
A: Neehar Polavarapu's answer above looks good but there is one problem, when you push the joystic 45 degree two motors get maximum speed. To solve this you have to rotate input -45 degree so that when push joystick 90 degree (forward) two motors get maximum speed. 
Rotate:
angle = -45;
double rad = angle*M_PI/180;
newX = x * cos(rad) - y * sin(rad);
newY = y * cos(rad) + x * sin(rad);
Then use the newX and newY for Neehar Polavarapu's formula above.
