using System; namespace Science.Physics.GeneralPhysics { /// /// Vector is inherited to many physical quantities. /// public class Vector : Dimension { public delegate Vector Field(Position x, Time t); public delegate Vector FunctionOfPosition(Position x); public delegate Vector FunctionOfTime(Time t); private double x=0.0,y=0.0,z=0.0; private bool xv=false, yv=false, zv=false; private double sdx = 0.0, sdy = 0.0, sdz = 0.0; public Vector() { } private Vector.Field g; public Vector(Vector.Field f) { g = f; } public Vector.Field VectorField { get { return g; } set { g = value; } } private FunctionOfPosition gp; public Vector(FunctionOfPosition fp) { gp = fp; } public Vector.FunctionOfPosition VectorFunctionOfPosition { get { return gp; } set { gp = value; } } private FunctionOfTime gt; public Vector(FunctionOfTime ft) { gt = ft; } public Vector.FunctionOfTime VectorFunctionOfTime { get { return gt; } set { gt = value; } } public void Set(Position xx, Time t) { Vector v = g(xx, t); x = v.X; y = v.Y; z = v.Z; } public void Set(Position xx) { Vector v = gp(xx); x = v.X; y = v.Y; z = v.Z; } public void Set(Time t) { Vector v = gt(t); x = v.X; y = v.Y; z = v.Z; } public double Norm { get{return Math.Sqrt(x*x+y*y+z*z);} } public virtual double X { get{return x;} set{x=value;} } public virtual double Y { get{return y;} set{y=value;} } public virtual double Z { get{return z;} set{z=value;} } public bool XVariableQ { get{return xv;} set{xv=value;} } public bool YVariableQ { get{return yv;} set{yv=value;} } public bool ZVariableQ { get{return zv;} set{zv=value;} } public double StandardDeviationOfX { get { return sdx; } set { sdx = value; } } public double StandardDeviationOfY { get { return sdy; } set { sdy = value; } } public double StandardDeviationOfZ { get { return sdz; } set { sdz = value; } } public static Vector operator +(Vector a, Vector b) { Vector c = new Vector(); c.X = a.X + b.X; c.Y = a.Y + b.Y; c.Z = a.Z + b.Z; return c; } public static Vector operator -(Vector a, Vector b) { Vector c = new Vector(); c.X = a.X - b.X; c.Y = a.Y - b.Y; c.Z = a.Z - b.Z; return c; } public static Scalar operator *(Vector a, Vector b) { Scalar s = new Scalar(); s.Magnitude = a.X*b.X + a.Y*b.Y + a.Z*b.Z; return s; } public static Vector operator %(Vector a, Vector b) // CrossProduct { Vector c = new Vector(); c.X = a.Y*b.Z - a.Z*b.Y; c.Y = a.Z*b.X - a.X*b.Z; c.Z = a.X*b.Y - a.Y*b.X; return c; } public static Vector operator *(Scalar a, Vector b) { Vector c = new Vector(); c.X = a.Magnitude*b.X; c.Y = a.Magnitude*b.Y; c.Z = a.Magnitude*b.Z; return c; } public static Vector operator *(Vector b, Scalar a) { Vector c = new Vector(); c.X = a.Magnitude*b.X; c.Y = a.Magnitude*b.Y; c.Z = a.Magnitude*b.Z; return c; } public static Vector operator *(double a, Vector b) { Vector c = new Vector(); c.X = a*b.X; c.Y = a*b.Y; c.Z = a*b.Z; return c; } public static Vector operator *(Vector b, double a) { Vector c = new Vector(); c.X = a*b.X; c.Y = a*b.Y; c.Z = a*b.Z; return c; ; } public override string ToString() { string res = ""; res += this.X.ToString() + " +/- " + this.StandardDeviationOfX.ToString() + " i "; if (this.Y >= 0.0) res += " +"; res += this.Y.ToString() + " +/- " + this.StandardDeviationOfY.ToString() + " j "; if (this.Z >= 0.0) res += " +"; res += this.Z.ToString() + " +/- " + this.StandardDeviationOfZ.ToString() + " k "; return res; } public string ToONLYmks() { string res = ""; this.DimensionTransformCharge(); res += "(kg^" + this.DimensionMass.ToString(); res += " m^" + this.DimensionLength.ToString(); res += " s^" + this.DimensionTime.ToString() + ")"; return res; } } }