【问题标题】:Porting Rhinoscriptsyntax from Python to C#将 Rhinoscriptsyntax 从 Python 移植到 C#
【发布时间】:2018-10-30 22:35:47
【问题描述】:

我正在将一组 RhinoScript (Python) 函数移植到 C#,以便开发一组自定义 Grasshopper 组件。

我的问题是我无法访问某些 RhinoScript 方法,例如 VectorUnitize()VectorScale()PointAdd()

我似乎在 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 = ????

【问题讨论】:

    标签: c# python grasshopper rhino3d


    【解决方案1】:

    根据Vector3d documentation of the Add function,您还可以使用 Vector3d 的重载 + 运算符。对于这些几何类型中的大多数,RhinoCommon 提供了预期的重载。

    因此,要缩放一个向量,您可以将它与一个标量相乘,在您的情况下是 alignmentseparationcohesion

    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;
    

    【讨论】:

      【解决方案2】:

      在这里你可以看到所有的 rhino 脚本功能是如何使用 Rhino Common 实现的: https://github.com/mcneel/rhinoscriptsyntax/tree/rhino-6.x/Scripts/rhinoscript

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-16
        • 1970-01-01
        • 2018-03-30
        • 2011-02-06
        • 1970-01-01
        相关资源
        最近更新 更多