Skip to content

Instantly share code, notes, and snippets.

@danleyb2
Created August 15, 2017 05:20
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danleyb2/ce6d2b82b1556f7bb7dc3c5d2bccb2fc to your computer and use it in GitHub Desktop.
Save danleyb2/ce6d2b82b1556f7bb7dc3c5d2bccb2fc to your computer and use it in GitHub Desktop.
Plot a given number of equally spaced circumferance cordinates on a x,y center with given radius
import math
from math import pi
def points_on_circumference(center=(0, 0), r=50, n=100):
return [
(
center[0]+(math.cos(2 * pi / n * x) * r), # x
center[1] + (math.sin(2 * pi / n * x) * r) # y
) for x in xrange(0, n + 1)]
print points_on_circumference(center=(-10,-10),r=50)
@tomMulholland
Copy link

tomMulholland commented Dec 11, 2019

Thanks for your code!
Just a note, xrange (line 11) is deprecated in Python 3

@johnthagen
Copy link

A Python 3 version that uses type hints:

import math
from typing import List, Tuple


def points_on_circumference(
    center: Tuple[float, float] = (0.0, 0.0), r: float = 50.0, n: int = 100
) -> List[Tuple[float, float]]:
    return [
        (
            center[0] + (math.cos(2 * math.pi / n * x) * r),  # x
            center[1] + (math.sin(2 * math.pi / n * x) * r),  # y
        )
        for x in range(0, n + 1)
    ]


print(points_on_circumference(center=(-10.0, -10.0), r=50.0))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment