C# rotate list of planes not working

I’m trying to rotate a list of planes using the following C#, but the planes output by A isn’t rotated.

private void RunScript(List<Plane> x, double y, ref object A)
  {
    for(int i = 0;i < x.Count;i++){
      x[i].Rotate(de2r(y), x[i].ZAxis, x[i].Origin);
    }
    A = x;
  }

  // <Custom additional code> 
  double de2r(double a){
    return a * (Math.PI / 180);
  }

If I change the x input from List to Item, they would rotate just fine.
If I create a new input z (mesh), and rotate those mesh with the list of planes (code below), the mesh would rotate.

private void RunScript(List<Mesh> z, List<Plane> x, double y, ref object A)
  {
    for(int i = 0;i < x.Count;i++){
      z[i].Rotate(de2r(y), x[i].ZAxis, x[i].Origin);
    }
    A = z;
  }

  // <Custom additional code> 
  double de2r(double a){
    return a * (Math.PI / 180);
  }

What am I doing wrong in the first code snippet? why aren’t the planes rotating?

private void RunScript(List<Plane> x, double y, ref object A)
{
  var angle = de2r(y);
  for(int i = 0;i < x.Count;i++){
    var pln = x[i];
    pln.Rotate(angle, x[i].ZAxis, x[i].Origin);
    x[i] = pln;
  }
  A = x;
}
2 Likes

Planes are structs. You need to get them out of the list (which creates a copy) modify the copy, then put it back into the list.

Plane p = x[i];
p.Rotate(de2r(y), x[i].ZAxis, x[i].Origin);
x[i] = p;

In your current code, you are rotating a copy of the plane in the list, and then forgetting about that copy.

1 Like