View Single Post
  #9   Spotlight this post!  
Unread 22-09-2013, 15:22
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,077
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Converting Two joystick values into a vector

Quote:
Originally Posted by magnets View Post
The getTheta method I posted doesn't really do what you want.
I'm not really sure what you want.
Your post was linked to mine, with no quoting context provided. But I assume the pronoun "you" above refers not to me, but the OP, right?

I agree with you that the OP's problem statement is not entirely clear.

Quote:
public static double getTheta(double x, double y){
double z = Math.atan2(y,x);
double degrees = z * (180.0 / Math.PI); // convert to degrees
degrees = (degrees > 0.0 ? degrees : (360.0 + degrees)); // correct discontinuity
System.out.println(degrees+"t");
return degrees;
}
Your code above gives the angle in degrees measured counter-clockwise from the positive X axis.

You can get the same result, without the need for conditional logic, with this computation:

180/pi*atan2(-y,-x) + 180

If however you want the angle in degrees measured clockwise from the positive Y axis, this will do that:

180/pi*atan2(-x,-y) + 180......(see below)

Code:
// RLaB version 2.1.05 Copyright (C) 1992-97 Ian Searle


x=0;  y=1;  180/pi*atan2(-x,-y)+180
        0  

x=1;  y=1;  180/pi*atan2(-x,-y)+180
       45  

x=1;  y=0;  180/pi*atan2(-x,-y)+180
       90  

x=1;  y=-1; 180/pi*atan2(-x,-y)+180
      135  

x=0;  y=-1; 180/pi*atan2(-x,-y)+180
      180  

x=-1; y=-1; 180/pi*atan2(-x,-y)+180
      225  

x=-1; y=0;  180/pi*atan2(-x,-y)+180
      270  

x=-1; y=1;  180/pi*atan2(-x,-y)+180
      315  

x=-0; y=1;  180/pi*atan2(-x,-y)+180
      360


Last edited by Ether : 22-09-2013 at 18:18.