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 accessing 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 (not much :/):
// Find the alignment Vector
Vector3d aVec = AlignmentVector(neighborAgents, neighborAgentsDistances);
if (aVec.Length > 0)
{
aVec.Unitize();
}
aVec = ????