0

我正在尝试偏移 Point3DCollection 中的一个点,但无法将其转换为新位置。文本框显示第一个点的 0,0,0 虽然我正在对其进行 3,3,3 的偏移。以下代码有什么问题:

var result = new Point3DCollection(n);

var pt1 = new Point3D(0, 0, 0);
var pt2 = new Point3D(5, 5, 5);

result.Add(pt1);
result.Add(pt2);  
result[0].Offset(3,3,3);
textbox1.Text = result[0].X + "," + result[0].Y + "," + result[0].Z;
4

1 回答 1

1

See under "remarks" here: http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.point3d.offset.aspx

So result[0] does not give you a reference to the object but a copy, so that you change the offset of that copy and not the one in your collection.

If you need to work with a collection, one solution would be to replace your object in the collection and with a new Point3D object at the same index.

于 2012-11-06T08:09:45.540 回答