Go to Post Not all FIRST people are nuts. Some are threaded holes, rivets, velcro, or zip-ties. Anything but duct-tape. - Richard Wallace [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 03:02.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi