forked from Dan-Piker/K2Goals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCyclicQuad.cs
76 lines (67 loc) · 2.31 KB
/
CyclicQuad.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Rhino.Geometry;
namespace KangarooSolver.Goals
{
/// <summary>
/// Tries to make the 4 vertices of a quad lie on a common circle.
/// Should be used in conjunction with planarize.
/// Can be used for generating circular meshes, which have useful offset properties for beam structures.
/// </summary>
public class CyclicQuad : GoalObject
{
public double Strength;
public CyclicQuad()
{
}
public CyclicQuad(int[] P, double k)
{
PIndex = P;
Move = new Vector3d[4];
Weighting = new double[4];
Strength = k;
}
public CyclicQuad(Point3d[] P, double k)
{
PPos = P;
Move = new Vector3d[4];
Weighting = new double[4];
Strength = k;
}
public override void Calculate(List<KangarooSolver.Particle> p)
{
Point3d P1 = p[PIndex[0]].Position;
Point3d P2 = p[PIndex[1]].Position;
Point3d P3 = p[PIndex[2]].Position;
Point3d P4 = p[PIndex[3]].Position;
Point3d Center =
(
(new Circle(P1, P2, P3)).Center +
(new Circle(P2, P3, P4)).Center +
(new Circle(P3, P4, P1)).Center +
(new Circle(P4, P1, P2)).Center
) * 0.25;
double D1 = Center.DistanceTo(P1);
double D2 = Center.DistanceTo(P2);
double D3 = Center.DistanceTo(P3);
double D4 = Center.DistanceTo(P4);
double AvgDist = 0.25 * (D1 + D2 + D3 + D4);
double stretchfactor;
stretchfactor = 1.0 - AvgDist / D1;
Move[0] = (Center - P1) * stretchfactor;
stretchfactor = 1.0 - AvgDist / D2;
Move[1] = (Center - P2) * stretchfactor;
stretchfactor = 1.0 - AvgDist / D3;
Move[2] = (Center - P3) * stretchfactor;
stretchfactor = 1.0 - AvgDist / D4;
Move[3] = (Center - P4) * stretchfactor;
Weighting[0] = Strength;
Weighting[1] = Strength;
Weighting[2] = Strength;
Weighting[3] = Strength;
}
}
}