Formulas I created for the area of any curved closed shape

80 Views Asked by At

Basically the main idea behind it is this: you take a random curved closed shape like this: enter image description here

Then, since this can't be a function because for one x-value there's more than one y-value, you use the x-axis as a divisor, and you break the shape in two parts; i'll call the above the axis one "P" and the below one "Q". Then you choose as many coordinates as you want from the shape border, and use this program I wrote to find the Lagrange polynomial:

import numpy as np
from scipy.interpolate import lagrange
import matplotlib.pyplot as plt

x = np.array([*your x coordinates*])
y = np.array([*your y coordinates*])

poly = lagrange(x, y)

x_interp = np.linspace(min(x), max(x), 1000)
y_interp = poly(x_interp)

print("Lagrange polynomial:")
print(poly)

plt.scatter(x, y, color='red', label='nodes')
plt.plot(x_interp, y_interp, label='Polynomial', linewidth=2)
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.title('Lagrange interpolation')
plt.grid(True)
plt.show()

This also plots the graph for you. What this does is to create a polynomial which resembles at best the shape's curve, and an infinite amount of points would technically lead to a perfect precision, but there could be other factors. Anyways, then you integrate this polynomial in the interval the shape is defined in, in this example [-3,5]. This would be an approx. of the area of P. For Q you would take the same steps, but the integral has to be an absolute value, this because Q is under the x-axis. Formally the equations would be: $$ A_T = \lim\limits_{n\to\infty}\biggl(\int_{a}^{b} p_n^{P}(x)dx + \biggl|\int_{a}^{b} p_n^{Q}(x)dx\biggl|\biggl) = $$ $$ \lim\limits_{n\to\infty}\biggl(\int_{a}^{b} \biggl[\sum_{i=1}^{n} y_i^{P}\prod_{\substack{j=0}\\ {j\neq i}}^{n}\frac{x-x_j}{x_i-x_j}\biggl] dx + \biggl|\int_{a}^{b} \biggl[\sum_{i=1}^{n} y_i^{Q}\prod_{\substack{j=0}\\ {j\neq i}}^{n}\frac{x-x_j}{x_i-x_j}\biggl] dx\biggl|\biggl) $$
And in case of a x-axis simmetry: $$ A_T = \lim\limits_{n\to\infty}2\biggl(\int_{a}^{b} p_n^{P}(x)dx\biggl) $$ $$ \lim\limits_{n\to\infty}2\biggl(\int_{a}^{b} \biggl[\sum_{i=1}^{n} y_i^{P}\prod_{\substack{j=0}\\ {j\neq i}}^{n}\frac{x-x_j}{x_i-x_j}\biggl] dx\biggl) $$ Let me know what do you think about this. I'm aware of many numerical integrations method but as far as i searched it up, no one seems to have thought of this. If you think there are mistakes PLEASE point them out, and I'd be glad to discuss peacefully.