20 #region Using Statements 21 using System.Collections.Generic;
31 public static class TSConvexHull
33 #region public enum Approximation 34 public enum Approximation
51 public static int[] Build(List<TSVector> pointCloud, Approximation factor)
53 List<int> allIndices =
new List<int>();
55 int steps = (int)factor;
57 for (
int thetaIndex = 0; thetaIndex < steps; thetaIndex++)
60 FP theta = TSMath.Pi / (steps - 1) * thetaIndex;
61 FP sinTheta = FP.Sin(theta);
62 FP cosTheta = FP.Cos(theta);
64 for (
int phiIndex = 0; phiIndex < steps; phiIndex++)
67 FP phi = ((2 * FP.One) * TSMath.Pi) / (steps - 0) * phiIndex - TSMath.Pi;
68 FP sinPhi = FP.Sin(phi);
69 FP cosPhi = FP.Cos(phi);
71 TSVector dir =
new TSVector(sinTheta * cosPhi, cosTheta, sinTheta * sinPhi);
73 int index = FindExtremePoint(pointCloud, ref dir);
74 allIndices.Add(index);
80 for (
int i = 1; i < allIndices.Count; i++)
82 if (allIndices[i - 1] == allIndices[i])
83 { allIndices.RemoveAt(i - 1); i--; }
86 return allIndices.ToArray();
92 private static int FindExtremePoint(List<TSVector> points,ref TSVector dir)
95 FP current = FP.MinValue;
97 TSVector point; FP value;
99 for (
int i = 1; i < points.Count; i++)
103 value = TSVector.Dot(ref point, ref dir);
104 if (value > current) { current = value; index= i; }