# Area of a triangle in 3D: C# code

|The area of a triangle in 3D space can easily be calculated using **Heron’s Formula**.

The C# code below contains a method that returns the area of a triangle formed by 3 points. This code is written for RhinoCommon, though can be easily adapted for any C# application. ‘Point3d’ is a collection of XYZ coordinates for a single point, and the DistanceTo method returns a double equivalent to the Euclidean distance between the two points.

public double AreaOfTriangle(Point3d pt1, Point3d pt2, Point3d pt3) { double a = pt1.DistanceTo(pt2); double b = pt2.DistanceTo(pt3); double c = pt3.DistanceTo(pt1); double s = (a + b + c) / 2; return Math.Sqrt(s * (s-a) * (s-b) * (s-c)); }

## References

One Comment