Skip to content

Instantly share code, notes, and snippets.

@loopspace
Created May 29, 2025 23:49
Show Gist options
  • Save loopspace/40adecafcc7b28f33af1a1d306fcca6f to your computer and use it in GitHub Desktop.
Save loopspace/40adecafcc7b28f33af1a1d306fcca6f to your computer and use it in GitHub Desktop.
Code to work out the area of the quadrilateral defined by joining each vertex to the next-but-one midpoint of an edge, where the original quadrilateral has vertices (0,0), (2,0), (a,b), and (0,2).
def AC(a,b):
return [ 2*a/(a+2*b+4), (2*b+4)/(a+2*b+4)]
def AD(a,b):
return [ (2*a+2*b-2)/(a+2*b-1), b/(a+2*b-1)]
def BD(a,b):
return [ (a+2)*(2*a+b-2)/(4*a+3*b-4), b*(2*a+b)/(4*a+3*b-4)]
def BC(a,b):
return [ a*(a+2)/(3*a+b+2), (a+2)*(b+2)/(3*a+b+2) ]
def Area(a,b):
ac = AC(a,b)
ad = AD(a,b)
bd = BD(a,b)
bc = BC(a,b)
return (ac[0] * ad[1] + ad[0] * bd[1] + bd[0] * bc[1] + bc[0] * ac[1] - ac[1] * ad[0] - ad[1] * bd[0] - bd[1] * bc[0] - bc[1] * ac[0])/2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment