Is it possible to calculate the surface area of a 2D polygon with any shape, using a set of 3D vertices? For instance, what would be the surface area of the given figure?
var polygon = new Polygon([new Point(0,0,0), new Point(5,8,2), new Point(11,15,7)])
polygon.areaIfPolygonIs3D()
--> some expected result, regardless of the number of vertices in the polygon...
Remember that polygons have only one surface. They are flat shapes that can be triangular, trapezoidal, irregular, and positioned at various angles in 3D space – almost like pieces of paper oriented in different ways.
I've attempted to flatten the polygon by rotating it, then applied a basic formula for calculating the area of an irregular 2D polygon which currently works in my code (formula: ). However, I faced challenges in aligning all vertices so the polygon lies flat (with all "z" values as 0) leading me to explore other options. If someone can assist in resolving this issue or offer guidance after spending a day relearning high school geometry concepts, it would be highly appreciated!
I have access to Points and Edges (created using point.to(point)), where Edges possess 'theta' (edge.theta()) and 'phi' (edge.phi()).
If anyone could provide insight on how to proceed here, following extensive effort to refresh my memory on geometry principles, it would be immensely helpful!
var locatorRho = function(x,y,z) {
return Math.sqrt(x*x + y*y + z*z);
}
var locatorTheta = function(x,y) {
return Math.atan2(y,x);
};
var locatorPhi = function(x,y,z) {
return z == 0 ? Math.PI_2 : Math.acos(z/locatorRho(x, y, z));
}
// rotates a point based on another point ('locator'), along with their 2D angle ('theta') and 3D angle ('phi')
Point.prototype.rotateBy = function(locator, theta, phi) {
phi = (phi == undefined ? 0 : phi);
var relativeX = this.x() - locator.x();
var relativeY = this.y() - locator.y();
var relativeZ = this.z() - locator.z();
var distance = locatorRho(relativeX, relativeY, relativeZ);
var newTheta = locatorTheta(relativeX, relativeY) + theta;
var newPhi = locatorPhi(relativeX, relativeY, relativeZ) + phi;
this._x = locatorX(distance, newTheta, newPhi) + locator.x();
this._y = locatorY(distance, newTheta, newPhi) + locator.y();
this._z = locatorZ(distance, newPhi) + locator.z();
}
Polygon.prototype.signedArea = function() {
var vertices = this.vertices();
var area = 0;
for(var i=0, j=1, length=vertices.length; i<length; ++i, j=(i+1)%length) {
area += vertices[i].x()*vertices[j].y() - vertices[j].x()*vertices[i].y();
}
return 0.5*area
}
Polygon.prototype.areaIfPolygonIs2D = function() {
return Math.abs(rotatedFlatCopy.signedArea())
}
Polygon.prototype.areaIfPolygonIs3D = function() {
... assistance needed here, feeling stuck ...
}
var vertices = [some number of Points, e.g., new Point(x,y,z)]
var polygon = new Polygon(vertices)
var polygon.areaIfPolygonIs3D()
--> desired outcome