Created
August 15, 2017 05:20
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
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
Thanks for your code!
Just a note, xrange (line 11) is deprecated in Python 3