forked from Dan-Piker/K2Goals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLengthMultiple.cs
54 lines (48 loc) · 1.51 KB
/
LengthMultiple.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Rhino.Geometry;
namespace KangarooSolver.Goals
{
/// <summary>
/// Make distance between 2 points a multiple of some given factor
/// </summary>
public class LengthMultiple : GoalObject
{
public double Stiffness;
public double Factor;
public LengthMultiple()
{
}
public LengthMultiple(int S, int E, double F, double k)
{
PIndex = new int[2] { S, E };
Move = new Vector3d[2];
Weighting = new double[2];
Stiffness = k;
Factor = F;
}
public LengthMultiple(Point3d S, Point3d E, double F, double k)
{
PPos = new Point3d[2] { S, E };
Move = new Vector3d[2];
Weighting = new double[2];
Stiffness = k;
Factor = F;
}
public override void Calculate(List<KangarooSolver.Particle> p)
{
Vector3d current = p[PIndex[1]].Position - p[PIndex[0]].Position;
double LengthNow = current.Length;
double RestLength = (Math.Round(LengthNow / Factor)) * Factor;
double stretchfactor = 1.0 - RestLength / LengthNow;
Vector3d SpringMove = 0.5 * current * stretchfactor;
Move[0] = SpringMove;
Move[1] = -SpringMove;
Weighting[0] = 2*Stiffness;
Weighting[1] = 2*Stiffness;
}
}
}