PolarCoordinates.md (1310B)
1 # Polar Coordinates 2 3 **Source:** Deep Learning 4 5 **Chapter:** 1 6 7 **Definition:** The polar coordinate system is a coordinate system where we define coordinates not by their distances but rather by the distance and also the angle theta made between the line segment and the origin. 8 9 NORMAL SYSTEM: 10 11 (x,y) -> where x is the distance on the x-axis and y is the distance on the y-axis from the origin. 12 13 POLAR COORDINATE SYSTEM: 14 15 (r,theta) -> r is the distance (length of r) and theta is the angle (in radians) between the positive x-axis and the line segment created by connecting the origin with the coordinate. 16 17 IMPLEMENTATION OF CONVERSION FROM POLAR TO CARTESIAN: 18 19 ```python3 20 21 # convert from polar coordinates to cartesian and vice versa 22 import math 23 24 def polarToCart(r, theta): 25 print("Polar Coordinates: \t" + str(r) + " " + str(theta)) 26 x = math.cos(theta) * r 27 y = math.sin(theta) * r 28 print("Cartesian Coordinates: \t" + str(x) + " " + str(y)) 29 return (x,y) 30 31 def cartToPolar(x,y): 32 print("Cartesian Coordinates: \t" + str(x) + " " + str(y)) 33 r = math.sqrt(x**2 + y**2) 34 theta = math.asin(y/r) 35 print("Polar Coordinates: \t" + str(r) + " " + str(theta)) 36 37 r = 2.3 38 theta = 1.38 39 print("POLAR TO CART:") 40 x,y = polarToCart(r,theta) 41 print() 42 print("CART TO POLAR:") 43 cartToPolar(x,y) 44 45 ```