In this blog post we will investigate two types of coordinates used to identify the location of a point on a 2D plan:
- Cartesian Coordinates (x,y)
- Polar Coordinates (r,θ)
Both sets of coordinates have their own applications and are often used in computer systems and video games. After reviewing how these sets of coordinates work we will write a Python script based on trigonometric formulas to convert Cartesian coordinates into Polar coordinates and vice versa.
Cartesian CoordinatesPolar Coordinates
Cartesian coordinates are used to identify the exact location of a point on a 2D plan. Two perpendicular axis (x axis and y axis) meet at the origin (0,0). The (x,y) cartesian coordinates are based on the distance of a point from these axis.
Look at the canvas below to understand how Cartesian coordinates work:
When using Cartesian coordinates, we can divide the 2D plan into four quadrants as follows:
Polar coordinates are also used to identify the exact location of a point on a 2D plan. Using a polar coordinate system, each point on a plane is determined by a distance from a reference point and an angle from a reference direction. The reference point is called the pole, and the ray from the pole in the reference direction is the polar axis.
Look at the canvas below to understand how Polar coordinates work:
Polar to Cartesian Coordinates Conversion Formulas
Using trigonometric formulas we can easily convert Cartesian coordinates to Polar coordinates and vice-versa.
Python Turtle Implementation
Your Task
Adapt the above Python code to generate random polar coordinates and apply the conversion to calculate and output the matching Cartesian coordinates.
Python Turtle Radar Animation
To apply the conversion formulas we have created a radar animation using Python Turtle: