I am currently using the following code to convert from Cartesian (x, y) coordinates to an angle (0-360 degrees):
def anti_clockwise(x,y):
alpha = degrees(atan2(y,x))
return (alpha + 360) % 360
I am now trying to go back by specifying a distance (eg, 100) and angle (result from above code) to return to some x, y coordinates.
I have been able to get this to work using a simple trigonometry function, but this is limited to 0-90 degrees. Is there any way of getting the x, y coordinates for the full 0-360 degrees range?
Following is what I'm using but realized I didn't convert back to radians!
def get_coord(magnitude, degrees):
angle = radians(degrees)
x = magnitude * cos(angle)
y = magnitude * sin(angle)
return x, y
The following has been tested ans is working:
def get_coord(magnitude, degrees):
angle = radians(degrees)
x = magnitude * cos(angle)
y = magnitude * sin(angle)
return x, y
The problem was not converting to radians during the angle calculation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.