I’m in the process of porting a collection of rhinoscript (python) functions to C# in order to develop a collection of custom grasshopper components. My problem is I’m having trouble access some rhinoscript methods such as VectorUnitize(), VectorScale() and PointAdd(). I can’t seem to find any references that include these in C#. Does anyone have any experience with this kind of thing as to point me in the right direction?
Rhinoscript I’m working from:
# FIND THE ALIGNMENT VECTOR
aVec = self.AlignmentVector(neighborAgents, neighborAgentsDistances)
if rs.VectorLength(aVec) > 0:
aVec = rs.VectorUnitize(aVec)
aVec = rs.VectorScale(aVec, self.alignment)
# FIND THE SEPARATION VECTOR
sVec = self.SeparationVector(neighborAgents, neighborAgentsDistances)
if rs.VectorLength(sVec) > 0:
sVec = rs.VectorUnitize(sVec)
sVec = rs.VectorScale(sVec, self.separation)
# FIND THE COHESION VECTOR
cVec = self.CohesionVector(neighborAgents)
if rs.VectorLength(cVec) > 0:
cVec = rs.VectorUnitize(cVec)
cVec = rs.VectorScale(cVec, self.cohesion)
# ADD ALL OF THE VECTOR TOGETHER to find the new position of the agent
acc = [0, 0, 0]
acc = rs.PointAdd(acc, aVec)
acc = rs.PointAdd(acc, sVec)
acc = rs.PointAdd(acc, cVec)
# update the self vector
self.vec = rs.PointAdd(self.vec, acc)
self.vec = rs.VectorUnitize(self.vec)
What I’ve got so far:
// if there is more than 0 neighbors within the neighbor radius then perform the follow actions
if (neighborAgents.Count > 0)
{
// Find the alignment Vector
Vector3d aVec = AlignmentVector(neighborAgents, neighborAgentsDistances);
if (aVec.Length > 0)
aVec.Unitize();
aVec = aVec * Alignment;
Vector3d sVec = SeparationVector(neighborAgents, neighborAgentsDistances);
if (sVec.Length > 0)
sVec.Unitize();
sVec = sVec * Separation;
Vector3d cVec = CohesionVector(neighborAgents);
if (cVec.Length > 0)
sVec.Unitize();
cVec = cVec * Cohesion;
}