如何使用X,Y和Z坐标编写代码以添加两个向量a,b。 下面的代码显示了我确切到达的地方。
public Vector(float _x, float _y, float _z)
{
float X, Y, Z;
X = _x;
Y = _y;
Z = _z;
Vector _vector = new Vector(X, Y, Z);
}
public static Vector operator +(Vector _a, Vector _b)
{
return new Vector(); //_a.X + _b.X , _a.Y + _b.Y, _a.Z + _b.Z
}
答案 0 :(得分:6)
根据传入参数创建属性。然后你可以在班上的任何地方使用它们:
public class Vector
{
public float X { get; set; }
public float Y { get; set; }
public float Z { get; set; }
public Vector(float _x, float _y, float _z)
{
X = _x;
Y = _y;
Z = _z;
}
public static Vector operator +(Vector _a, Vector _b)
{
return new Vector(_a.X + _b.X, _a.Y + _b.Y, _a.Z + _b.Z);
}
}
答案 1 :(得分:2)
public struct Vector
{
public float X { get; }
public float Y { get; }
public float Z { get; }
public Vector(float x, float y, float z)
{
X = x;
Y = y;
Z = z;
}
public static Vector operator +(Vector a, Vector b)
{
return new Vector(a.X + b.X , a.Y + b.Y, a.Z + b.Z);
}
}
注意: