OK it took me a while to figure out how to do it for my own project and this is one of the top posts that come up when googling it, so here is how it is done.
First there is two aspects, motor distribution and speed. Normally distribution and speed is determined by x and y respectfully. However this doesn't work for us.
Instead speed is equal to the distance from the center. (which we will refer to as 0,0).
Next to get the distribution we need the angle of the point with respect to the X-axis.
Specifically: 0 degrees being X=MaxRight, Y=0; 90 degrees X=0, Y=MaxUp; 180 degrees y=0, X= maxleft; 270 degrees x=0, y=maxdown
Let +1=100% of power and -1=-100% power (ie reverse)
Then (* == degrees)
90* => +1, +1
180* => -1,+1
270* => -1,-1
360*/0* => +1,-1
Now as the points move around the circle there needs to be a transition between +1 and -1. Specifically in the first quadrant:
Quadrant one (angle <90*)
at 0* it is +1, -1
at 22.5* it is +1, -.5
at 45* it is +1,0
at 67.5 it is +1, +.5
at 90* it is +1, +1.
Now programmablly the code is
double right_dist;
double left_dist;
if(angle <= 90){
left_dist= +1;
if(angle<45.0){
right_dist= -1*((45.0-angle)/45.0);
}
else{
right_dist= 1*( (angle-45.0)/45.0);
}
}
else if(angle <= 180){
angle = angle - 90;
right_dist= +1;
if(angle<45.0){
left_dist= 1*((45.0-angle)/45.0);
}
else{
left_dist= -1*( (angle-45.0)/45.0);
}
}
else if(angle <= 270){
angle = angle - 180;
left_dist= -1;
if(angle<45.0){
right_dist= 1*((45.0-angle)/45.0);
}
else{
right_dist= -1*( (angle-45.0)/45.0);
}
}
else{ // if(angle <= 360){
angle = angle - 270;
right_dist= -1;
if(angle<45.0){
left_dist= -1 *((45.0-angle)/45.0);
}
else{
left_dist= 1*( (angle-45.0)/45.0);
}
}
motor_left_speed=left_dist*distance
motor_right_speed=right_dist*distance