Calculate area of plane in 3D space using X, Y, Z

980 Views Asked by At

I have a polygon that's positioned on the earth. For each point, I have:

The latitude in degrees (x) The longitude in degress (y) The altitude above sea level in meters.

An example of one of my points is { x: 144.99533074458003, y: -32.39730248504104, z: 263.24070871460185 }

Now, in my application, a user draws a polygon in space, and I need to determine the area of that polygon. The user could draw a polygon around a door, or a roof maybe. Sometimes even a sidewalk.

Once the user is done, I have a list of all the points they selected.

An example could be this:

DOOR = [
  { x: 144.99533074458003, y: -32.39730248504104, z: 263.24070871460185 }, // First point, bottom left
  { x: 144.99533197184215, y: -32.39730172327194, z: 267.1472276731874 }, // Top left
  { x: 144.99534689346532, y: -32.39726245542652, z: 267.04165748822226 }, // Top right
  { x: 144.99534752390096, y: -32.39726407569114, z: 263.24884951333394 }, // Bottom right
  { x: 144.99533074458003, y: -32.39730248504104, z: 263.24070871460185 }, // Last point, same as first to close the loop.
];

The issue now, is that I need to figure out the approximate area between all these points. I know that the polygon won't be perfectly flat, but I can even it out if needed to give an approximation.

My current strategy is as follows:

  • Find the distance between each of the points using the Haversine Formula.

  • Determine the height difference between the two points by subtracting z2 from z1.

  • Find the actual length of the line using Pythagorus.

  • Get the angle of the line relative to the horizontal plane using (Math.atan2(end.y - start.y, end.x - start.x) * 180) / Math.PI (Please excuse the Javascript, that's what I'm working in).

  • I then have a list of all the lengths and the angles of each line.

  • I then convert each angle to Radians.

  • Then I generate x and y values like this:

      endX = start.x + length * Math.cos(angle)
      endY = start.y + length * Math.sin(angle)
    
  • This give me a list of the X.Y values of the points.

  • I then calculate the area using this formula

This strategy works when my plane is nearly horizontal, but as soon as I try use it on a vertical surface, I get incorrect results.

I guess there's a few questions here, and any help will be greatly appreciated.

Edit: This would need to work for any number of coordinates greater than 3, not only 4 sided polygons.

Thanks!

1

There are 1 best solutions below

4
On

An easier approach would be calculating the projected area using the same formula you provided but ignoring the z-coordinate (let's call it $A_p$ for demonstration). Then you can calculate the area of the original polygon by multiplying $A_p$ by $\sec \theta$, where $\theta$ is the angle between the polygon and the horizontal.