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.
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
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: