我正在将一个Python( RhinoScript )函数集合移植到C#,以便开发一个定制的Grasshopper组件集合。
我的问题是我在访问VectorUnitize()、VectorScale()和PointAdd()等RhinoScript方法时遇到了问题。
在C#中,我似乎找不到任何包含这些内容的引用。有没有人对这类事情有经验,可以给我指明正确的方向?
我在RhinoScript上工作:
# 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)到目前为止我得到的(不是很多:/):
// Find the alignment Vector
Vector3d aVec = AlignmentVector(neighborAgents, neighborAgentsDistances);
if (aVec.Length > 0)
{
aVec.Unitize();
}
aVec = ????发布于 2018-11-01 05:20:17
根据Vector3d documentation of the Add function,您还可以使用Vector3d的重载+运算符。对于这些几何类型中的大多数,RhinoCommon提供了预期的重载。
因此,要缩放一个向量,您需要将其与标量相乘,在本例中为alignment、separation和cohesion。
Vector3d vec1 = getyourvector();
vec1.Unitize();
vec1 *= alignment;
Vector3d vec2 = getyourvector();
vec2.Unitize();
vec2 *= cohesion;
Vector3d vec3 = getyourvector();
vec3.Unitize();
vec3 *= separation;
Vector3d acc;
acc += vec1;
acc += vec2;
acc += vec3;发布于 2018-11-06 15:02:22
在这里,您可以看到所有rhino脚本函数是如何使用Rhino Common:https://github.com/mcneel/rhinoscriptsyntax/tree/rhino-6.x/Scripts/rhinoscript实现的
https://stackoverflow.com/questions/53073852
复制相似问题