Files
speckle-sharp-connectors/Sdk/Speckle.Common.MeshTriangulation/Poly3.cs
T
kekesidavid 48e66f9084 Mesh generator logic to triangulate 2D and 3D surfaces (#529)
* added mesh generator logic to triangulate 2D and 3D surfaces from polygon inputs

* removed empty folder

* checking hole polygon vertex order, added comments

* csharpier

* added MeshTriangulation project to Local sln

* added reference to MeshTriangulator in Tekla Converters
2025-01-29 15:27:09 +01:00

37 lines
782 B
C#

using Speckle.DoubleNumerics;
namespace Speckle.Common.MeshTriangulation;
public readonly struct Poly3
{
public List<Vector3> Vertices { get; }
public Poly3()
{
Vertices = new List<Vector3>();
}
public Poly3(List<Vector3> vertices)
{
Vertices = vertices ?? throw new ArgumentNullException(nameof(vertices));
}
// helper function, only works on polygons with at least 3 vertices
public Vector3 GetNormal()
{
if (Vertices.Count < 3)
{
throw new InvalidOperationException("Polygon must have at least 3 points to calculate a normal.");
}
var v1 = Vertices[1] - Vertices[0];
var v2 = Vertices[2] - Vertices[0];
return Vector3.Normalize(Vector3.Cross(v1, v2));
}
public void Reverse()
{
Vertices.Reverse();
}
}