Polar coordinates

2025/12/27

Type
Learning Resource
Format
Glossary Article
Version
General
Subject Tags
Code
Assets
All else
Copyright 2016-2026, GDQuest
Created
2026/02/16
Updated
2025/12/27

Polar coordinates

Polar coordinates represent a position using an angle and a distance from a point. This is an alternative to Cartesian coordinates, which use distances from a point along axes.

Among other applications, polar coordinates are useful to represent:

Converting from polar to Cartesian coordinates in 2D in Godot

Given an angle and a distance, you can take a unit vector pointing to the right, rotate it by the angle, and multiply it by the distance to convert polar coordinates to Cartesian ones.

Here's a GDScript code example that uses polar coordinates to generate a random position within a circle:

var random_angle := randf_range(0.0, 2.0 * PI)
var random_direction := Vector2(1.0, 0.0).rotated(random_angle)
var random_distance := randf_range(60.0, 120.0)
position = random_direction * random_distance

This code generates a random angle between 0 and 2π, a random direction by rotating a unit vector by the random angle, and a random distance between 60 and 120. By multiplying the direction by the distance, we get a random position within a circle.

Become an Indie Gamedev with GDQuest!

Don't stop here. Step-by-step tutorials are fun but they only take you so far.

Try one of our proven study programs to become an independent Gamedev truly capable of realizing the games you’ve always wanted to make.

Nathan

Founder and teacher at GDQuest
  • Starter Kit
  • Learn Gamedev from Zero
Check out GDSchool

You're welcome in our little community

Get help from peers and pros on GDQuest's Discord server!

20,000 membersJoin Server

Contribute to GDQuest's Free Library

There are multiple ways you can join our effort to create free and open source gamedev resources that are accessible to everyone!