我也遇到了同样的问题,谢谢你的回复。
这是我的解决方案:
if (reset == false && run == true)
{
for ( int i = 0;i < locations.Count;i++)
{
double stepX = rnd.Next(-1, 2) * 5 * rnd.NextDouble();
double stepY = rnd.Next(-1, 2) * 5 * rnd.NextDouble();
double stepZ = rnd.Next(-1, 2) * 5 * rnd.NextDouble();
Vector3d transform = new Vector3d(stepX, stepY, stepZ);
locations[i] += transform;
// Constrain points to boundary conditions
Point3d ptx = locations[i]; // make temp variable to hold all points
ptx.X = CV.Constrain(ptx.X, 0, bX - 1); // access X coordinates and modify them
locations[i] = ptx; // assign new X coordinates to points in List
Point3d pty = locations[i];
pty.Y = CV.Constrain(pty.Y, 0, bY - 1);
locations[i] = pty;
Point3d ptz = locations[i];
ptz.Z = CV.Constrain(ptz.Z, 0, bZ - 1);
locations[i] = ptz;
Component.ExpireSolution(true);
}
}