【发布时间】:2018-10-29 05:38:58
【问题描述】:
我正在创建一个包含许多不同参数的代理对象列表,但我不确定如何使用循环访问我的所有对象的特定参数......我正在寻找什么要做的是从我所有的代理那里获得所有的 Point3d 职位。我该怎么做?
// Define Agent class
class Agent
{
Point3d Pos = new Point3d();
Vector3d Vec = new Vector3d();
int Alignment;
double Separation;
double Cohesion;
double NeighborRadius;
public Agent(Point3d pos, Vector3d vec, int alignment, double separation, double cohesion, double neighborRadius)
{
Pos = pos;
Vec = vec;
Alignment = alignment;
Separation = separation;
Cohesion = cohesion;
NeighborRadius = neighborRadius;
}
}
protected override void SolveInstance(IGH_DataAccess DA)
{
// Initialize Agents
for (int i = 0; i < agents; i++)
{
double xPos = RandomfromDouble(0.0, boundx);
double yPos = RandomfromDouble(0.0, boundy);
double zPos = RandomfromDouble(0.0, boundz);
Point3d pos = new Point3d(xPos, yPos, zPos); // Create Agent Start Position
Vector3d vec = new Vector3d(xPos + 1, yPos, zPos); // Create Agent Start Vector
Agent agent = new Agent(pos, vec, alignment, separation, cohesion, neighborRadius);
allAgents.Add(agent);
agentPositions.Add(pos);
}
}
【问题讨论】:
-
allAgents.Select(z => z.Pos)
标签: c# grasshopper