Skip to content

Instantly share code, notes, and snippets.

@ejmurray
Created February 23, 2015 08:27
Show Gist options
  • Save ejmurray/3c7f141dddab79ef6d12 to your computer and use it in GitHub Desktop.
Save ejmurray/3c7f141dddab79ef6d12 to your computer and use it in GitHub Desktop.
area of a curcle using two functions
#!/usr/bin/python
# encoding: utf-8
"""
calculate the area of a circle using two functions
"""
__author__ = 'Ernest'
import math
def radius(x1, x2, y1, y2):
"""
:param x1: x-position 1
:param x2: x-position 2
:param y1: y-position 1
:param y2: y-position 2
:return: distance between two points
"""
deltax = (x2 - x1)**2
# print deltax
deltay = (y2 - y1)**2
# print deltay
distance = math.sqrt(deltax + deltay)
# print 'radius', distance
return distance
def area(xc, xp, yc, yp):
"""
:param xc:
:param xp:
:param yc:
:param yp:
:return:
"""
circle_area = math.pi * radius(xc, xp, yc, yp)**2
# print circle_area
return circle_area
print area(1, 4, 2, 6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment