News Alert: Experts Exchange Confirmed as Safe in Cloudbleed Leak Read More
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebApplication1
{
public class Algorithm
{
private Mesh _mesh { get; set; }
public Algorithm(Mesh mesh)
{
_mesh = mesh;
}
private double SignedVolumeOfTriangle(Vector3 p1, Vector3 p2, Vector3 p3)
{
var v321 = p3.X * p2.Y * p1.Z;
var v231 = p2.X * p3.Y * p1.Z;
var v312 = p3.X * p1.Y * p2.Z;
var v132 = p1.X * p3.Y * p2.Z;
var v213 = p2.X * p1.Y * p3.Z;
var v123 = p1.X * p2.Y * p3.Z;
return (1.0 / 6.0) * (-v321 + v231 + v312 - v132 - v213 + v123);
}
public double VolumeOfMesh()
{
double volume = 0.0;
Vector3[] vertices = _mesh.Vertices;
int[] triangles = _mesh.Triangles;
for (int i = 0; i < _mesh.Triangles.Length; i += 3)
{
Vector3 p1 = vertices[triangles[i + 0]];
Vector3 p2 = vertices[triangles[i + 1]];
Vector3 p3 = vertices[triangles[i + 2]];
volume += SignedVolumeOfTriangle(p1, p2, p3);
}
return Math.Abs(volume);
}
}
public class Mesh
{
public Mesh(Vector3[] _vertices, int[] _triangles)
{
Vertices = _vertices;
Triangles = _triangles;
}
public Vector3[] Vertices { get; set; }
public int[] Triangles { get; set; }
}
public class Vector3
{
public Vector3(double x, double y, double z)
{
X = x;
Y = y;
Z = z;
}
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
}
}
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
asp day pilot | 3 | 21 | |
Store results in vb.net | 3 | 22 | |
Winform Module - What is the ASP.Net equiv | 2 | 23 | |
Dot Net 4.6.1 installation fails on W2012 R2 server | 14 | 21 |
Join the community of 500,000 technology professionals and ask your questions.