private static float3 Circumcenter(ref Triad triad, ref NativeList <float3> vertices) { float3 vA = vertices[triad.A], vB = vertices[triad.B], vC = vertices[triad.C]; float dA = vA.x * vA.x + vA.y * vA.y; float dB = vB.x * vB.x + vB.y * vB.y; float dC = vC.x * vC.x + vC.y * vC.y; float aux1 = (dA * (vC.y - vB.y) + dB * (vA.y - vC.y) + dC * (vB.y - vA.y)); float aux2 = -(dA * (vC.x - vB.x) + dB * (vA.x - vC.x) + dC * (vB.x - vA.x)); float div = (2 * (vA.x * (vC.y - vB.y) + vB.x * (vA.y - vC.y) + vC.x * (vB.y - vA.y))); return(float3(aux1 / div, aux2 / div, 0f)); }
private static void Triad(out Triad triad, int A, int B, int C, ref NativeArray <float3> vertices) { float3 vA = vertices[A], vB = vertices[B], vC = vertices[C], center; float dA = vA.x * vA.x + vA.y * vA.y; float dB = vB.x * vB.x + vB.y * vB.y; float dC = vC.x * vC.x + vC.y * vC.y; float aux1 = (dA * (vC.y - vB.y) + dB * (vA.y - vC.y) + dC * (vB.y - vA.y)); float aux2 = -(dA * (vC.x - vB.x) + dB * (vA.x - vC.x) + dC * (vB.x - vA.x)); float div = (2 * (vA.x * (vC.y - vB.y) + vB.x * (vA.y - vC.y) + vC.x * (vB.y - vA.y))); if (div == 0) { //throw new System.Exception("div by zero."); } center = new float3(aux1 / div, aux2 / div, 0f); triad = new Triad(A, B, C, center, (center.x - vA.x) * (center.x - vA.x) + (center.y - vA.y) * (center.y - vA.y)); }
public void Execute() { int vCount = inputVertices.Length, sCount = inputSitesVertices.Length, totalCount = vCount + sCount, A, B, C, tCount, nIndex; Triad triad; float3 center, pt; NativeList <int> neighbors = new NativeList <int>(10, Allocator.Temp); NativeArray <IndexedVertex> neighborsList = new NativeArray <IndexedVertex>(0, Allocator.Temp); UIntPair edge; bool check = false; outputVertices.Clear(); outputVertices.Capacity = totalCount; outputTriangles.Clear(); outputTriangles.Capacity = sCount * 3; //Merge base vertices and voronoi sites in a single list for (int i = 0; i < vCount; i++) { outputVertices.Add(inputVertices[i]); } for (int i = 0; i < sCount; i++) { outputVertices.Add(inputSitesVertices[i]); } for (int i = 0; i < vCount; i++) { //A being the base vertice A = i; check = inputUnorderedHullEdges.TryGetValue(A, out edge); if (check) { continue; } neighbors.Clear(); tCount = inputSites.PushValues(ref i, ref neighbors); neighborsList.Release(); neighborsList = new NativeArray <IndexedVertex>(tCount, Allocator.Temp); center = inputVertices[A]; for (int v = 0; v < tCount; v++) { nIndex = neighbors[v]; pt = inputSitesVertices[nIndex] - center; IndexedVertex iv = new IndexedVertex() { index = vCount + nIndex, angle = plane == AxisPair.XY ? atan2(pt.y, pt.x) : atan2(pt.z, pt.x) }; neighborsList[v] = iv; } neighborsList.Sort(new SortIndexedVertex()); for (int v = 0; v < tCount; v++) { B = neighborsList[v].index; C = v + 1; if (C >= tCount) { C = neighborsList[0].index; } else { C = neighborsList[v + 1].index; } if (check) { if (inputUnorderedHullEdges.TryGetValue(B - vCount, out edge) || inputUnorderedHullEdges.TryGetValue(C - vCount, out edge)) { continue; } } triad = new Triad(A, B, C, float3(0f), 0f); outputTriangles.Add(triad); } } }