Polygon area calculation using Latitude and Longitude generated from Cartesian space and a world file

I checked on internet for various polygon area formulas(or code) but did not find any one good or easy to implement. Now I have written the code snippet to calculate area of a polygon drawn on earth surface. The polygon can have n vertices with each vertex has having its own latitude longitude. Few Important … Read more

Calculating the area under a curve given a set of coordinates, without knowing the function

The numpy and scipy libraries include the composite trapezoidal (numpy.trapz) and Simpson’s (scipy.integrate.simps) rules. Here’s a simple example. In both trapz and simps, the argument dx=5 indicates that the spacing of the data along the x axis is 5 units. import numpy as np from scipy.integrate import simps from numpy import trapz # The y … Read more

MATLAB, Filling in the area between two sets of data, lines in one figure

Building off of @gnovice’s answer, you can actually create filled plots with shading only in the area between the two curves. Just use fill in conjunction with fliplr. Example: x=0:0.01:2*pi; %#initialize x array y1=sin(x); %#create first curve y2=sin(x)+.5; %#create second curve X=[x,fliplr(x)]; %#create continuous x value array for plotting Y=[y1,fliplr(y2)]; %#create y values for out … Read more

Calculate area of polygon given (x,y) coordinates

Implementation of Shoelace formula could be done in Numpy. Assuming these vertices: import numpy as np x = np.arange(0,1,0.001) y = np.sqrt(1-x**2) We can redefine the function in numpy to find the area: def PolyArea(x,y): return 0.5*np.abs(np.dot(x,np.roll(y,1))-np.dot(y,np.roll(x,1))) And getting results: print PolyArea(x,y) # 0.26353377782163534 Avoiding for loop makes this function ~50X faster than PolygonArea: %timeit … Read more