Created
March 30, 2022 14:48
-
-
Save CodeDrome/606ce783ad01140b6f8e793cb54f45b1 to your computer and use it in GitHub Desktop.
quadrilateralareascoordinates.py
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
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