public bool Equals(VectorF other) { if (object.ReferenceEquals(this, other)) { return(true); } if (object.ReferenceEquals(null, other)) { return(false); } var otherComponents = other._components; if (_components.Length != otherComponents.Length) { return(false); } #if HAS_CODECONTRACTS Assume(_components.Length == otherComponents.Length); #endif for (int dimension = 0; dimension < _components.Length; dimension++) { if (!_components[dimension].Equals(otherComponents[dimension])) { return(false); } } return(true); }
public float GetDistanceSquared(VectorF other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } var otherComponenets = other._components; if (otherComponenets.Length != _components.Length) { throw new ArgumentOutOfRangeException(nameof(other)); } if (_components.Length == 0) { return(0.0f); } var sum = MathEx.Square(_components[0] - otherComponenets[0]); for (var i = 1; i < _components.Length; i++) { sum += MathEx.Square(_components[i] - otherComponenets[i]); } return(sum); }
public float GetDot(VectorF right) { if (right == null) { throw new ArgumentNullException(nameof(right)); } var rightComponents = right._components; if (_components.Length != rightComponents.Length) { throw new ArgumentOutOfRangeException(nameof(right)); } if (_components.Length == 0) { return(0.0f); } var sum = _components[0] * rightComponents[0]; for (int i = 1; i < _components.Length; i++) { sum += _components[i] * rightComponents[i]; } return(sum); }
public VectorF(VectorF source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } _components = Clone(source._components); }
public VectorF GetScaled(float scalar) { var scaled = new VectorF(_components.Length); var scaledComponents = scaled._components; for (int i = 0; i < scaledComponents.Length; i++) { scaledComponents[i] = _components[i] * scalar; } return(scaled); }
public VectorF GetProjected(VectorF other) { if (other.Dimensions != Dimensions) { throw new ArgumentOutOfRangeException(nameof(other)); } var scalarDenominator = GetMagnitudeSquared(); return(scalarDenominator == 0.0f ? other : GetScaled(GetDot(other) / scalarDenominator)); }
public VectorF GetNegative() { var negated = new VectorF(_components.Length); var negatedComponents = negated._components; for (var i = 0; i < _components.Length; i++) { negatedComponents[i] = -_components[i]; } return(negated); }
public VectorF GetQuotient(float divisor) { var quotient = new VectorF(_components.Length); var quotientComponents = quotient._components; for (int i = 0; i < _components.Length; i++) { quotientComponents[i] = _components[i] / divisor; } return(quotient); }
public float GetAngleBetween(VectorF other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } if (other._components.Length != _components.Length) { throw new ArgumentOutOfRangeException(nameof(other)); } return((float)Math.Acos( GetDot(other) / (float)Math.Sqrt(GetMagnitudeSquared() * other.GetMagnitudeSquared()))); }
public static VectorF CreateUnit(int size, int dimension) { if (size <= 0) { throw new ArgumentOutOfRangeException(nameof(size)); } if (dimension >= size) { throw new ArgumentOutOfRangeException(nameof(dimension)); } var result = new VectorF(size); result.Set(dimension, 1.0f); return(result); }
public void Subtract(VectorF right) { if (right == null) { throw new ArgumentNullException(nameof(right)); } if (_components.Length != right._components.Length) { throw new ArgumentOutOfRangeException(nameof(right)); } var rightComponents = right._components; for (int i = 0; i < _components.Length; i++) { _components[i] -= rightComponents[i]; } }
public VectorF GetDiffernce(VectorF right) { if (right == null) { throw new ArgumentNullException(nameof(right)); } if (_components.Length != right._components.Length) { throw new ArgumentOutOfRangeException(nameof(right)); } var difference = new VectorF(_components.Length); var diffComponents = difference._components; var rightComponents = right._components; for (int i = 0; i < _components.Length; i++) { diffComponents[i] = _components[i] - rightComponents[i]; } return(difference); }
public VectorF GetSum(VectorF right) { if (right == null) { throw new ArgumentNullException(nameof(right)); } if (_components.Length != right._components.Length) { throw new ArgumentOutOfRangeException(nameof(right)); } var sum = new VectorF(_components.Length); var sumComponents = sum._components; var rightComponents = right._components; for (int i = 0; i < _components.Length; i++) { sumComponents[i] = _components[i] + rightComponents[i]; } return(sum); }
public float GetDistance(VectorF other) { return((float)Math.Sqrt(GetDistanceSquared(other))); }