Skip to content

Commit 5960215

Browse files
committed
Changed to use GoalObject & added some new ones
1 parent f54bf83 commit 5960215

30 files changed

+549
-332
lines changed

Anchor.cs

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Rhino.Geometry;
7+
8+
namespace KangarooSolver.Goals
9+
{
10+
/// <summary>
11+
/// Fix a point in place
12+
/// </summary>
13+
public class Anchor : GoalObject
14+
{
15+
public double Strength;
16+
public Point3d Pt;
17+
18+
public Anchor()
19+
{
20+
}
21+
22+
/// <summary>
23+
/// Construct a new Anchor object by particle index and target position
24+
/// </summary>
25+
/// <param name="Id">The integer index of the particle to anchor.</param>
26+
/// <param name="P">The target position to keep the particle at.</param>
27+
/// <param name="K">Strength of the Anchor. For an absolute anchor, you can use double.MaxValue here.</param>
28+
public Anchor(int Id, Point3d P, double k)
29+
{
30+
PIndex = new int[1] { Id };
31+
Move = new Vector3d[1];
32+
Weighting = new double[1] { k };
33+
Strength = k;
34+
Pt = P;
35+
}
36+
37+
/// <summary>
38+
/// Construct a new Anchor object by position.
39+
/// </summary>
40+
/// <param name="P">Particle starting position. Also used as the target position to keep the particle at.</param>
41+
/// <param name="K">Strength of the Anchor. For an absolute anchor, you can use double.MaxValue here.</param>
42+
public Anchor(Point3d P, double k)
43+
{
44+
PPos = new Point3d[1] { P };
45+
Move = new Vector3d[1];
46+
Weighting = new double[1]{k};
47+
Strength = k;
48+
Pt = P;
49+
}
50+
51+
public override void Calculate(List<KangarooSolver.Particle> p)
52+
{
53+
Move[0] = Pt - p[PIndex[0]].Position;
54+
Weighting[0] = Strength;
55+
}
56+
}
57+
}

Angle.cs

+3-16
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace KangarooSolver.Goals
1212
/// by S.M.L. Adriaenssens, M.R.Barnes
1313
/// http://formfindinglab.princeton.edu/wp-content/uploads/2011/09/Spline-Beam.pdf
1414
/// </summary>
15-
public class Angle : IGoal
15+
public class Angle : GoalObject
1616
{
1717
public double EI;
1818
public double RestAngle;
@@ -48,12 +48,7 @@ public Angle(Line L0, Line L1, double RA, double Strength)
4848
RestAngle = RA;
4949
}
5050

51-
public Point3d[] PPos { get; set; }
52-
public int[] PIndex { get; set; }
53-
public Vector3d[] Move { get; set; }
54-
public double[] Weighting { get; set; }
55-
56-
public void Calculate(List<KangarooSolver.Particle> p)
51+
public override void Calculate(List<KangarooSolver.Particle> p)
5752
{
5853
Point3d P0 = p[PIndex[0]].Position;
5954
Point3d P1 = p[PIndex[1]].Position;
@@ -86,14 +81,6 @@ public void Calculate(List<KangarooSolver.Particle> p)
8681
Weighting[1] = EI;
8782
Weighting[2] = EI;
8883
Weighting[3] = EI;
89-
}
90-
public IGoal Clone()
91-
{
92-
return this.MemberwiseClone() as IGoal;
93-
}
94-
public object Output(List<Particle> p)
95-
{
96-
return null;
97-
}
84+
}
9885
}
9986
}

AngleMultiple.cs

+2-15
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace KangarooSolver.Goals
1010
/// <summary>
1111
/// Make angle between 2 lines a multiple of some given factor
1212
/// </summary>
13-
public class AngleMultiple : IGoal
13+
public class AngleMultiple : GoalObject
1414
{
1515
public double EI;
1616
public double AngleFactor;
@@ -37,12 +37,7 @@ public AngleMultiple(Line L0, Line L1, double AF, double Strength)
3737
AngleFactor = AF;
3838
}
3939

40-
public Point3d[] PPos { get; set; }
41-
public int[] PIndex { get; set; }
42-
public Vector3d[] Move { get; set; }
43-
public double[] Weighting { get; set; }
44-
45-
public void Calculate(List<KangarooSolver.Particle> p)
40+
public override void Calculate(List<KangarooSolver.Particle> p)
4641
{
4742
Point3d P0 = p[PIndex[0]].Position;
4843
Point3d P1 = p[PIndex[1]].Position;
@@ -77,13 +72,5 @@ public void Calculate(List<KangarooSolver.Particle> p)
7772
Weighting[2] = EI;
7873
Weighting[3] = EI;
7974
}
80-
public IGoal Clone()
81-
{
82-
return this.MemberwiseClone() as IGoal;
83-
}
84-
public object Output(List<Particle> p)
85-
{
86-
return null;
87-
}
8875
}
8976
}

ClampLength.cs

+3-17
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace KangarooSolver.Goals
77
/// Keep the length of a line between some upper and lower bounds
88
/// When it is between these lengths no force is applied
99
/// </summary>
10-
public class ClampLength : IGoal
10+
public class ClampLength : GoalObject
1111
{
1212
public double Upper;
1313
public double Lower;
@@ -37,12 +37,7 @@ public ClampLength(Point3d S, Point3d E, double U, double L, double k)
3737
Stiffness = k;
3838
}
3939

40-
public Point3d[] PPos { get; set; }
41-
public int[] PIndex { get; set; }
42-
public Vector3d[] Move { get; set; }
43-
public double[] Weighting { get; set; }
44-
45-
public void Calculate(List<KangarooSolver.Particle> p)
40+
public override void Calculate(List<KangarooSolver.Particle> p)
4641
{
4742
Vector3d current = p[PIndex[1]].Position - p[PIndex[0]].Position;
4843
double LengthNow = current.Length;
@@ -69,15 +64,6 @@ public void Calculate(List<KangarooSolver.Particle> p)
6964
Move[0] = Vector3d.Zero;
7065
Move[1] = Vector3d.Zero;
7166
}
72-
}
73-
public IGoal Clone()
74-
{
75-
return this.MemberwiseClone() as IGoal;
76-
}
77-
public object Output(List<Particle> p)
78-
{
79-
return null;
80-
}
81-
67+
}
8268
}
8369
}

CoLinear.cs

+2-15
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace KangarooSolver.Goals
99
{
10-
public class CoLinear : IGoal
10+
public class CoLinear : GoalObject
1111
{
1212
public double Strength;
1313
public double TargetArea;
@@ -42,12 +42,7 @@ public CoLinear(List<Point3d> V, double k)
4242
Strength = k;
4343
}
4444

45-
public Point3d[] PPos { get; set; }
46-
public int[] PIndex { get; set; }
47-
public Vector3d[] Move { get; set; }
48-
public double[] Weighting { get; set; }
49-
50-
public void Calculate(List<KangarooSolver.Particle> p)
45+
public override void Calculate(List<KangarooSolver.Particle> p)
5146
{
5247
int L = PIndex.Length;
5348
Point3d[] Pts = new Point3d[L];
@@ -66,13 +61,5 @@ public void Calculate(List<KangarooSolver.Particle> p)
6661
}
6762
}
6863

69-
public IGoal Clone()
70-
{
71-
return this.MemberwiseClone() as IGoal;
72-
}
73-
public object Output(List<Particle> p)
74-
{
75-
return null;
76-
}
7764
}
7865
}

CoPlanar.cs

+3-17
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace KangarooSolver.Goals
99
{
10-
public class CoPlanar : IGoal
10+
public class CoPlanar : GoalObject
1111
{
1212
public double Strength;
1313
public double TargetArea;
@@ -42,12 +42,7 @@ public CoPlanar(List<Point3d> V, double k)
4242
Strength = k;
4343
}
4444

45-
public Point3d[] PPos { get; set; }
46-
public int[] PIndex { get; set; }
47-
public Vector3d[] Move { get; set; }
48-
public double[] Weighting { get; set; }
49-
50-
public void Calculate(List<KangarooSolver.Particle> p)
45+
public override void Calculate(List<KangarooSolver.Particle> p)
5146
{
5247
int L = PIndex.Length;
5348
Point3d[] Pts = new Point3d[L];
@@ -65,15 +60,6 @@ public void Calculate(List<KangarooSolver.Particle> p)
6560
Weighting[i] = Strength;
6661
}
6762
}
68-
69-
public IGoal Clone()
70-
{
71-
return (IGoal)this.MemberwiseClone();
72-
}
73-
74-
public object Output(List<KangarooSolver.Particle> p)
75-
{
76-
return null;
77-
}
63+
7864
}
7965
}

CoSpherical.cs

+2-15
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace KangarooSolver.Goals
99
{
10-
public class CoSpherical : IGoal
10+
public class CoSpherical : GoalObject
1111
{
1212
public double Strength;
1313
public double TargetArea;
@@ -42,12 +42,7 @@ public CoSpherical(List<Point3d> V, double k)
4242
Strength = k;
4343
}
4444

45-
public Point3d[] PPos { get; set; }
46-
public int[] PIndex { get; set; }
47-
public Vector3d[] Move { get; set; }
48-
public double[] Weighting { get; set; }
49-
50-
public void Calculate(List<KangarooSolver.Particle> p)
45+
public override void Calculate(List<KangarooSolver.Particle> p)
5146
{
5247
int L = PIndex.Length;
5348
Point3d[] Pts = new Point3d[L];
@@ -66,13 +61,5 @@ public void Calculate(List<KangarooSolver.Particle> p)
6661
}
6762
}
6863

69-
public IGoal Clone()
70-
{
71-
return this.MemberwiseClone() as IGoal;
72-
}
73-
public object Output(List<Particle> p)
74-
{
75-
return null;
76-
}
7764
}
7865
}

Coincident.cs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Rhino.Geometry;
7+
8+
namespace KangarooSolver.Goals
9+
{
10+
public class Coincident : GoalObject
11+
{
12+
public double Strength;
13+
14+
public Coincident(Point3d P0, Point3d P1, double Strength)
15+
{
16+
this.Strength = Strength;
17+
PPos = new Point3d[2] { P0, P1 };
18+
Move = new Vector3d[2];
19+
Weighting = new Double[2] { Strength, Strength };
20+
}
21+
22+
public override void Calculate(List<KangarooSolver.Particle> p)
23+
{
24+
Move[0] = 0.5 * (p[PIndex[1]].Position - p[PIndex[0]].Position);
25+
Move[1] = -1 * Move[0];
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)