I am trying to make a component for the PolygonArea Goal in VisualStudio2019.
It was previously tested with a simple c# component with rhino and kangaroo up to date and worked.
//Code taken from GitHub (Kangaroo2, Daniel Picker) and modified
public class PolygonArea : GoalObject
{
public double Strength;
public double TargetArea;
public PolygonArea(List<Point3d> V, double Area, double k)
{
if(k <= 0)k = 1;
int L = V.Count;
PPos = V.ToArray();
Move = new Vector3d[L];
Weighting = new double[L];
for (int i = 0; i < L; i++)
{
Weighting[i] = k;
}
TargetArea = Area;
Strength = k;
}
public override void Calculate(List<KangarooSolver.Particle> p)
{
Vector3d temporalSum = Vector3d.Zero;
double TotalLength = 0;
int L = PIndex.Length;
for (int i = 1; i < L - 1; i++)
{
temporalSum += Vector3d.CrossProduct(p[PIndex[0]].Position - p[PIndex[i]].Position, p[PIndex[0]].Position - p[PIndex[(i + 1) % L]].Position);
}
for (int i = 0; i < L; i++)
{
TotalLength += p[PIndex[i]].Position.DistanceTo(p[PIndex[(i + 1) % L]].Position);
Move[i] = Vector3d.Zero;
}
double CurrentAreaDoubled = temporalSum.Length * 0.5;
double AreaShortage = TargetArea - CurrentAreaDoubled;
double Offset = AreaShortage / TotalLength;
temporalSum.Unitize();
for (int i = 0; i < L; i++)
{
int NextVert = (i + 1) % L;
Vector3d Edge = (p[PIndex[(i + 1) % L]].Position - p[PIndex[i]].Position);
Edge.Unitize();
Vector3d Pressure = Offset * Vector3d.CrossProduct(Edge, temporalSum);
Move[i] += Pressure;
Move[NextVert] += Pressure;
Weighting[i] = Strength;
}
}
}
(logic taken from Caculate area of polygon in 3D - Mathematics Stack Exchange)
However Visual Studio didn’t like the combo of versions of Kangaroo and Rhinocommon dlls (even with the latest version of rhinocommon it supposedly kangaroo was a later version, while when updating it it said it in VS it was exactly the same). Therefore went one version back in Kangaroo. Now not even the c# component works. Are IGoals treated differently in different versions of Kangaroo? Any advice on how to make it work?
(Initially: RhinoCommon + Kangaroo version 7.12.21313.6341, when pressing Start apparently RhinoCommon is 7.12.21313.6340, Second try: Kangaroo 2.41)
Thank you for your time.
PS: Actually the Solver does run in both c# component and VS component, just the results are wrong.