-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeoAlgorithmUtils.cs
More file actions
78 lines (72 loc) · 2.29 KB
/
GeoAlgorithmUtils.cs
File metadata and controls
78 lines (72 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/********************************************************************************
** All rights reserved
** Auth: kay.yang
** E-mail: [email protected]
** Date: 6/30/2017 11:13:04 AM
** Version: v1.0.0
*********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using KayMath;
namespace KayAlgorithm
{
public class GeoAlgorithmUtils
{
public static bool IsOnSamePlane(GeoPointsArray3 points, ref GeoPlane plane)
{
if (points.Size() < 4)
{
return true;
}
int count = points.Size();
int i = 2;
Vector3 p = points[0];
for (; i < count; ++i)
{
p = points[i];
if (!GeoLineUtils.IsPointInLine3(points[0], points[1], ref p))
{
break;
}
}
if (i == count)
{
return true;
}
plane = GeoPlaneUtils.CreateFromTriangle(points[0], points[1], p);
i = 2;
int c = 2;
for (; i < count; ++i)
{
if (GeoPlaneUtils.IsPointOnPlane(plane.mNormal, plane.mD, points[i]))
{
c++;
}
}
return c == count;
}
public static GeoPointsArray2 BuildConvexHull(GeoPointsArray2 points)
{
points.Distinct();
return new GeoPointsArray2(JarvisConvex.BuildHull(points.mPointArray));
}
public static GeoPointsArray3 BuildConvexHull(GeoPointsArray3 points)
{
points.Distinct();
GeoPlane plane = new GeoPlane(Vector3.zero, 0);
if (IsOnSamePlane(points, ref plane))
{
GeoPointsArray2 point2 = new GeoPointsArray2(GeoPlaneUtils.PlaneTransformLocal(points.mPointArray, plane));
point2 = BuildConvexHull(point2);
return new GeoPointsArray3(GeoPlaneUtils.PlaneTransformGlobal(point2.mPointArray, plane));
}
else
{
return new GeoPointsArray3(QuickHull.BuildHull(points));
}
}
}
}