/// <summary> /// This function returns the difference of the input arguments as (Arg1 - Arg2). /// The function returns as a vector the vector difference of the two input vectors. /// The input arguments shall both be of the same dimensionality but may be either directions or vectors. /// If both input arguments are vectors they must be expressed in the same units, if both are directions a unitless result is produced. /// A zero difference vector produces a vector of zero magnitude. /// </summary> /// <param name="arg1"></param> /// <param name="arg2"></param> /// <returns></returns> public static IfcVector IfcVectorDifference(IfcDirection arg1, IfcVector arg2) { if (arg1 == null || arg2 == null || arg1.Dim != arg2.Dim) { return(null); } return(IfcVectorDifference(1, arg1, arg2.Magnitude, arg2.Orientation.Item)); }
/// <summary> /// Constructor accepting underlying data /// </summary> /// <param name="point"></param> /// <param name="direction"></param> public IfcLine(IfcCartesianPoint point, IfcVector direction) { if (point == null) { throw new ArgumentNullException("point"); } if (direction == null) { throw new ArgumentNullException("direction"); } this.Pnt = (IfcLinePnt)point; this.Dir = (IfcLineDir)direction; }
/// <summary> /// This function returns a vector whose components are normalized to have a sum of squares of 1.0. /// If the input argument is not defined or of zero length then null is returned. /// </summary> /// <param name="arg"></param> /// <returns></returns> public static IfcVector IfcNormalise(IfcVector arg) { if (arg == null) { throw new ArgumentNullException("arg"); } IfcDimensionCount1 Ndim; IfcDirection V = new IfcDirection(1, 0); IfcVector Vec = new IfcVector(new IfcDirection(1, 0), 1); doublewrapper Mag; Ndim = arg.Dim; V.DirectionRatios = arg.Orientation.Item.DirectionRatios; Vec.Magnitude = arg.Magnitude; Vec.Orientation = (IfcVectorOrientation)V; if (arg.Magnitude == 0) { return(null); } Vec.Magnitude = 1; Mag = 0; for (int i = 0; i < Ndim; i++) { Mag += V.DirectionRatios[i] * V.DirectionRatios[i]; } if (Mag <= 0) { return(null); } Mag = Math.Sqrt((double)Mag); for (int i = 0; i < Ndim; i++) { V.DirectionRatios[i] /= Mag; } Vec.Orientation = (IfcVectorOrientation)V; return(Vec); }
/// <summary> /// This function returns the vector that is the scalar multiple of the input vector. /// It accepts as input a scalar and a 'vector' which may be either a Direction or a Vector. /// The output is a Vector of the same units as the input vector or unitless if a direction is input. /// If either input argument is undefined then the returned vector is also undefined. /// </summary> /// <param name="scalar"></param> /// <param name="vec"></param> /// <returns></returns> public static IfcVector IfcScalarTimesVector(double scalar, IfcVector vec) { if (vec == null) { return(null); } IfcDirection V; double Mag; V = vec.Orientation.Item; Mag = scalar * vec.Magnitude; if (Mag < 0) { for (int i = 0; i < V.DirectionRatios.Items.Length; i++) { V.DirectionRatios[i] = -V.DirectionRatios[i]; } Mag = -Mag; } return(new IfcVector(IfcNormalise(V), Mag)); }