Skip to main content
added 39 characters in body
Source Link
Kirill L.
  • 13.9k
  • 2
  • 15
  • 50

R, 85 8181 78 bytes

function(i,h=chull(i),j=c(h,h[1]))round(sum((i[h,1]+i[j[-1],1])*diff%*%diff(-i[j,2]))/2)

Try it online!Try it online!

Takes input as a 2-column matrix - first for x, second for y. R's round actually uses banker's rounding method, so we are quite lucky here.

The code uses a built-in function to determine, which points form the convex hull, and then applies the standard formula \$\sum_{i}{(x_{i-1}+x)\cdot(y_{i-1}-y_i)}/2\$ to get the polygon surface area.

Thanks to Giuseppe for -3 bytes.

R, 85 81 bytes

function(i,h=chull(i),j=c(h,h[1]))round(sum((i[h,1]+i[j[-1],1])*diff(-i[j,2]))/2)

Try it online!

Takes input as a 2-column matrix - first for x, second for y. R's round actually uses banker's rounding method, so we are quite lucky here.

The code uses a built-in function to determine, which points form the convex hull, and then applies the standard formula \$\sum_{i}{(x_{i-1}+x)\cdot(y_{i-1}-y_i)}/2\$ to get the polygon surface area.

R, 85 81 78 bytes

function(i,h=chull(i),j=c(h,h[1]))round((i[h,1]+i[j[-1],1])%*%diff(-i[j,2])/2)

Try it online!

Takes input as a 2-column matrix - first for x, second for y. R's round actually uses banker's rounding method, so we are quite lucky here.

The code uses a built-in function to determine, which points form the convex hull, and then applies the standard formula \$\sum_{i}{(x_{i-1}+x)\cdot(y_{i-1}-y_i)}/2\$ to get the polygon surface area.

Thanks to Giuseppe for -3 bytes.

added 204 characters in body
Source Link
Kirill L.
  • 13.9k
  • 2
  • 15
  • 50

R, 8585 81 bytes

function(i,h=chull(i),j=c(h,h[1]))round(abs(sum((i[h,1]+i[j[-1],1])*diff(-i[j,2]))/2))

Try it online!Try it online!

Takes input as a 2-column matrix - first for x, second for y. R's round actually uses banker's rounding method, so we are quite lucky here.

The code uses a built-in function to determine, which points form the convex hull, and then applies the standard formula \$\sum_{i}{(x_{i-1}+x)\cdot(y_{i-1}-y_i)}/2\$ to get the polygon surface area.

R, 85 bytes

function(i,h=chull(i),j=c(h,h[1]))round(abs(sum((i[h,1]+i[j[-1],1])*diff(i[j,2]))/2))

Try it online!

Takes input as a 2-column matrix - first for x, second for y. R's round actually uses banker's rounding method, so we are quite lucky here.

R, 85 81 bytes

function(i,h=chull(i),j=c(h,h[1]))round(sum((i[h,1]+i[j[-1],1])*diff(-i[j,2]))/2)

Try it online!

Takes input as a 2-column matrix - first for x, second for y. R's round actually uses banker's rounding method, so we are quite lucky here.

The code uses a built-in function to determine, which points form the convex hull, and then applies the standard formula \$\sum_{i}{(x_{i-1}+x)\cdot(y_{i-1}-y_i)}/2\$ to get the polygon surface area.

Source Link
Kirill L.
  • 13.9k
  • 2
  • 15
  • 50

R, 85 bytes

function(i,h=chull(i),j=c(h,h[1]))round(abs(sum((i[h,1]+i[j[-1],1])*diff(i[j,2]))/2))

Try it online!

Takes input as a 2-column matrix - first for x, second for y. R's round actually uses banker's rounding method, so we are quite lucky here.