-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample of non-intersting code
More file actions
55 lines (44 loc) · 1.63 KB
/
example of non-intersting code
File metadata and controls
55 lines (44 loc) · 1.63 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
//example of code from Andrew Long -
//c# - get no intersections
//iStartingPositions is the base curve - so spiral in my case.
//Vector3d is a 3d array(x,y,z)
if (iReset || centers == null)
centers = new List<Point3d>(iStartingPositions);
List<Vector3d> totalMoves = new List<Vector3d>();
List<double> collisionCounts = new List<double>();
for (int i = 0; i < centers.Count; i++)
{
totalMoves.Add(new Vector3d(0.0, 0.0, 0.0));
collisionCounts.Add(0.0);
}
double collisionDistance = 2.0;
for (int i = 0; i < centers.Count; i++)
for (int j = i + 1; j < centers.Count; j++)
{
double d = centers[i].DistanceTo(centers[j]);
if (d > collisionDistance) continue;
Vector3d move = centers[i] - centers[j];
if (move.Length < 0.001) continue;
move.Unitize();
move *= 0.5 * (collisionDistance - d);
totalMoves[i] += move;
totalMoves[j] -= move;
collisionCounts[i] += 1.0;
collisionCounts[j] += 1.0;
}
for (int i = 0; i < centers.Count; i++)
if (collisionCounts[i] != 0.0)
centers[i] += totalMoves[i] / collisionCounts[i];
if (centers.Count < iMaxCenterCount)
{
List<int> splitIndices = new List<int>();
for (int i = 0; i < centers.Count - 1; i++)
if (centers[i].DistanceTo(centers[i + 1]) > 1.99)
splitIndices.Add(i + 1 + splitIndices.Count);
foreach (int splitIndex in splitIndices)
{
Point3d newCenter = 0.5 * (centers[splitIndex - 1] + centers[splitIndex]);
centers.Insert(splitIndex, newCenter);
}
}
oCenters = centers;