Skip to content

Instantly share code, notes, and snippets.

@CodeDrome
Created March 30, 2022 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeDrome/606ce783ad01140b6f8e793cb54f45b1 to your computer and use it in GitHub Desktop.
Save CodeDrome/606ce783ad01140b6f8e793cb54f45b1 to your computer and use it in GitHub Desktop.
quadrilateralareascoordinates.py
def calculate_area(c):
'''
Calculates the area of any quadrivaletral
from a list of x,y coordinates in the following format:
[[x1,y1],[x2,y2],[x3,y3],[x4,y4]]
'''
first = c[0][0]*c[1][1] + c[1][0]*c[2][1] + c[2][0]*c[3][1] + c[3][0]*c[0][1]
second = c[1][0]*c[0][1] + c[2][0]*c[1][1] + c[3][0]*c[2][1] + c[0][0]*c[3][1]
area = 0.5*(first - second)
return area
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment