На выходе получаю лист одинаковых элементов - C#
Формулировка задачи:
Доброго времени суток. Сразу к сути: в цикле создаются некие объекты и заносятся в лист. При дебаге видно, что они все абсолютно разные. Однако, на выходе получаю лист одинаковых элементов. На каждой итерации вновь созданный элемент забивает собой все предыдущие. В цикле нет ничего сверхъестественного. Подскажите, чем это может быть вызвано.
И собсна вырезка из класса математики
public struct Cyl
{
public TDPoint c1, c2;
public List<TDPoint> cir1, cir2;
}
public Cyl cylinder;
public class TDPoint
{
public float x;
public float y;
public float z;
public const float w = 1;
public TDPoint(float _x, float _y, float _z)
{
x = _x;
y = _y;
z = _z;
}
public TDPoint()
{
x = 0; y = 0; z = 0;
}
}
public void createCyl(float r, float h, int a)
{
cylinder.cir1 = new List<TDPoint>();
cylinder.cir1.Add(new TDPoint(r, 0f, 0f));
float angle = 10;
float[,] rOY = MathLib.RmatrixOY(angle);
//дальше происходят странные вещи
for (int i = 0; i < 36; i++)
{
cylinder.cir1.Add(MathLib.Multiply(rOY, cylinder.cir1[i]));
}
}//поворот вокруг Y
static public float[,] RmatrixOY(double a)
{
a = a * Math.PI / 180;
float[,] R = new float[4, 4] { { (float)Math.Cos(a), 0, (-1)* (float)Math.Sin(a), 0},
{ 0, 1, 0, 0},
{ (float)Math.Sin(a), 0, (float)Math.Cos(a), 0},
{ 0, 0, 0, 1}};
return R;
}
static public Form1.TDPoint Multiply(float[,] q, Form1.TDPoint p)
{
Form1.TDPoint tempPoint = p;
float[] tempArr = new float[4];
float[] arr = new float[4] { p.x, p.y, p.z, 1 };
int c = 0;
for (int j = 0; j < 4; j++)
{
for (int i = 0; i < 4; i++)
{
tempArr[c] += arr[i] * q[i, j];
}
c++;
}
tempPoint.x = (float)tempArr[0];
tempPoint.y = (float)tempArr[1];
tempPoint.z = (float)tempArr[2];
return tempPoint;
}Решение задачи: «На выходе получаю лист одинаковых элементов»
textual
Листинг программы
static public Form1.TDPoint Multiply(float[,] q, Form1.TDPoint p)
{
float[] tempArr = new float[4];
float[] arr = new float[4] { p.x, p.y, p.z, 1 };
int c = 0;
for (int j = 0; j < 4; j++)
{
for (int i = 0; i < 4; i++)
{
tempArr[c] += arr[i] * q[i, j];
}
c++;
}
return new Form1.TDPoint(tempArr[0], tempArr[1], tempArr[2]);
}