Click or drag to resize

Vector Class

A vector relative to a set of basis axes. The vector may change over time with respect to its axes.
Inheritance Hierarchy

Namespace:  AGI.Foundation.Geometry
Assembly:  AGI.Foundation.Core (in AGI.Foundation.Core.dll) Version: 24.3.420.0 (24.3.420.0)
Syntax
public abstract class Vector : DefinitionalObject, 
	IServiceProvider

The Vector type exposes the following members.

Constructors
  NameDescription
Protected methodVector
Initializes a new instance.
Protected methodVector(Vector, CopyContext)
Initializes a new instance as a copy of an existing instance.
Top
Properties
  NameDescription
Public propertyIsFrozen
Gets a value indicating whether this object is frozen. A frozen object cannot be modified and an ObjectFrozenException will be thrown if an attempt is made to do so.
(Inherited from DefinitionalObject.)
Top
Methods
  NameDescription
Public methodAdd
Add a vector to this one.
Protected methodCheckForSameDefinition(DefinitionalObject)
Checks to determine if another instance has the same definition as this instance and returns if it does. Derived classes MUST override this method and check all new fields introduced by the derived class for definitional equivalence. It is NOT necessary to check base class fields because the base class will already have done that. When overriding this method, you should NOT call the base implementation because it will return for all derived-class instances. Derived classes should check the type of other to preserve the symmetric nature of IsSameDefinition(Object).
(Overrides DefinitionalObjectCheckForSameDefinition(DefinitionalObject).)
Protected methodCheckForSameDefinition(Vector)
Checks to determine if another instance has the same definition as this instance and returns if it does. Derived classes MUST override this method and check all new fields introduced by the derived class for definitional equivalence. It is NOT necessary to check base class fields because the base class will already have done that. When overriding this method, you should NOT call the base implementation because it will return for all derived-class instances. Derived classes should check the type of other to preserve the symmetric nature of IsSameDefinition(Object).
Public methodClone
Clones this object using the specified context.
(Inherited from DefinitionalObject.)
Protected methodComputeCurrentDefinitionHashCode
Computes a hash code based on the current properties of this object. Derived classes MUST override this method and compute a hash code that combines: a unique hash code seed, the base implementation result, and the hash codes of all new fields introduced by the derived class which are used in the CheckForSameDefinition(DefinitionalObject) method.
(Overrides DefinitionalObjectComputeCurrentDefinitionHashCode.)
Public methodCreateVectorDerivative
Constructs a vector which represents a derivative of this vector.
Public methodCross
Produce the vector cross product between this vector and another one.
Public methodDivide(Double)
Divide this vector by a scale factor.
Public methodDivide(Scalar)
Divide this vector by a scale factor.
Public methodDot
Produce the vector dot product between this vector and another one.
Public methodEnumerateDependencies
Enumerates the dependencies of this object by calling EnumerateT(T) for each object that this object directly depends upon. Derived classes which contain additional dependencies MUST override this method, call the base implementation, and enumerate dependencies introduced by the derived class.
(Inherited from DefinitionalObject.)
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodFreeze
Freezes this object. Further attempts to modify it will result in an ObjectFrozenException.
(Inherited from DefinitionalObject.)
Protected methodFreezeAggregatedObjects
Called by Freeze to also freeze any objects that are considered to be a part of this object. Derived classes which contain additional aggregated objects MUST override this method, call the base implementation, and freeze aggregated objects introduced by the derived class. The objects that need to be frozen in this method are frequently created in this object's constructor and are not settable via properties.
(Inherited from DefinitionalObject.)
Public methodGetDefinitionHashCode
Gets a hash code representing the definition of this object.
(Inherited from DefinitionalObject.)
Public methodGetEvaluator
Gets an evaluator that can be used to find the Motion<Cartesian> of this vector at a given date with respect to the axes in which it is defined. See GetEvaluator(EvaluatorGroup) for details.
Public methodGetEvaluator(EvaluatorGroup)
Gets an evaluator that can be used to find the Motion<Cartesian> of this vector in its parent Axes at a given JulianDate. Consider using the methods of GeometryTransformer instead of calling this method directly.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetScalarElement(CartesianElement, Axes)
Gets a Scalar representing the X, Y, Z, or Magnitude of this vector.
Public methodGetScalarElement(CartesianElement, Axes, Int32)
Gets a Scalar representing the X, Y, Z, or Magnitude of this vector, or any derivative of those elements.
Public methodGetService
Gets the service object of the specified type.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodIsSameDefinition
Determines if this object has the same definition as another object.
(Inherited from DefinitionalObject.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodMultiply(Double)
Multiply this vector by a scale factor.
Public methodMultiply(Scalar)
Multiply this vector by a scale factor.
Public methodSubtract
Subtract a vector from this one.
Protected methodThrowIfFrozen
Throws ObjectFrozenException if this object IsFrozen. This method should be called from any method or property that modifies this object.
(Inherited from DefinitionalObject.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Operators
  NameDescription
Public operatorStatic memberAddition
Add two vectors together.
Public operatorStatic memberDivision(Vector, Scalar)
Divide a vector by a scalar.
Public operatorStatic memberDivision(Vector, Double)
Divide a vector by a scalar.
Public operatorStatic memberMultiply(Double, Vector)
Multiply a vector by a scalar.
Public operatorStatic memberMultiply(Scalar, Vector)
Multiply a vector by a scalar.
Public operatorStatic memberMultiply(Vector, Scalar)
Multiply a vector by a scalar.
Public operatorStatic memberMultiply(Vector, Double)
Multiply a vector by a scalar.
Public operatorStatic memberSubtraction
Subtract one vector from another.
Top
Examples

This example shows how to create a new Vector class.

C#
// Create a new type derived from Vector. This type will represent an inverted form
// of another vector.
public class InvertedVector : Vector
{
    public InvertedVector()
    {
    }

    public InvertedVector(Vector vectorToInvert)
    {
        m_vectorToInvert = vectorToInvert;
    }

    // The copy constructor, used to make a copy of the object.  Copy all of the
    // fields of the 'existingInstance' to the new object.  Reference types should
    // be passed through a call to UpdateReference so that the depth of the copy
    // can be controlled by the user.  See the documentation of the ICloneWithContext
    // interface for more information.
    protected InvertedVector(InvertedVector existingInstance, CopyContext context)
        : base(existingInstance, context)
    {
        m_vectorToInvert = context.UpdateReference(existingInstance.m_vectorToInvert);
    }

    // This is called to make a copy of the object, which it does by calling the
    // copy constructor above.
    public override object Clone(CopyContext context)
    {
        return new InvertedVector(this, context);
    }

    // This method is only called by the IsSameDefinition method in the base class to
    // determine if two vectors are equivalent. Derived classes MUST override this method and
    // check all new fields introduced by the derived class for definitional equivalence. It
    // is NOT necessary to check base class fields because the base class will already have
    // done that.
    protected sealed override bool CheckForSameDefinition(Vector other)
    {
        InvertedVector o = other as InvertedVector;
        return o != null &&
               AreSameDefinition(m_vectorToInvert, o.m_vectorToInvert);
    }

    // Called to determine a hash code for the current configuration of this object.
    // Derived classes MUST override this method and compute a hash code that combines: 
    // a unique hash code seed, the base implementation result, and the 
    // hash codes of all new fields introduced by the derived class which are used 
    // in the CheckForSameDefinition method.
    protected override int ComputeCurrentDefinitionHashCode()
    {
        return HashCode.Combine(typeof(InvertedVector).GetHashCode(),
                                base.ComputeCurrentDefinitionHashCode(),
                                GetDefinitionHashCode(m_vectorToInvert));
    }

    // Called to enumerate all of the other objects on which this object depends.  This
    // allows clients to navigate the graph of objects related to a computation.
    public override void EnumerateDependencies(DependencyEnumerator enumerator)
    {
        base.EnumerateDependencies(enumerator);
        enumerator.Enumerate(m_vectorToInvert);
    }

    // The vector to be inverted
    public Vector VectorToInvert
    {
        get { return m_vectorToInvert; }
        set { m_vectorToInvert = value; }
    }

    // This method is responsible for returning an instance of the private
    // Evaluator class. It should ensure that the properties are not null or
    // in an invalid state, and then use the evaluator group when it constructs
    // and returns an instance of the Evaluator.
    public override VectorEvaluator GetEvaluator(EvaluatorGroup group)
    {
        if (group == null)
            throw new ArgumentNullException("group");

        // Ensure that the properties are not null.
        if (VectorToInvert == null)
            throw new PropertyInvalidException("VectorToInvert", PropertyInvalidException.PropertyCannotBeNull);

        return group.CreateEvaluator<VectorEvaluator>(CreateEvaluator);
    }

    // This method, which is passed to the evaluator group in the method above as a delegate,
    // will only be called by the delegate if the evaluator does not yet exist in the group
    // and needs to be created.
    private VectorEvaluator CreateEvaluator(EvaluatorGroup group)
    {
        // In order to invert the vector, we first must evaluate it.
        // Get the evaluator that will allow us to do so.
        // Notice that we create this evaluator in the same EvaluatorGroup.
        var vectorEvaluator = VectorToInvert.GetEvaluator(group);
        return new Evaluator(group, vectorEvaluator);
    }

    private Vector m_vectorToInvert;

    // This is the definition of the Evaluator that is used to actually evaluate this Vector.
    // Because it is a private, nested class, it is not visible outside of the InvertedVector class.
    // This is ok, though, because once it is created users only interact with it via a reference
    // to its base class: VectorEvaluator.
    private sealed class Evaluator : VectorEvaluator
    {
        // An evaluator should not store any data that the user will be able to change
        // after creating the evaluator.  This sometimes requires that data required by the
        // evaluator be copied or frozen using the IFreezable interface.
        public Evaluator(EvaluatorGroup group, VectorEvaluator vectorEvaluator)
            : base(group)
        {
            m_vectorEvaluator = vectorEvaluator;
        }

        // The Evaluator's copy constructor will be called from the Clone method.
        // Don't forget to call the base class implementation!
        private Evaluator(Evaluator existingInstance, CopyContext context)
            : base(existingInstance, context)
        {
            // For non-evaluator reference types, we would use context.UpdateReference to
            // allow the context to update the references we hold.
            // This evaluator does not have any non-evaluator reference fields.

            // For evaluators, just assign the reference directly - we'll call UpdateReference later.
            m_vectorEvaluator = existingInstance.m_vectorEvaluator;

            // Always call UpdateEvaluatorReferences at the end of the copy constructor.
            // This is where references to evaluators will be updated.
            UpdateEvaluatorReferences(context);
        }

        // This method is used by the EvaluatorGroup system to avoid redundant evaluations. The
        // EvaluatorGroup may call it on your evaluator in order to replace your evaluator's
        // reference to another evaluator with a reference to a version that caches its last
        // result.
        public override void UpdateEvaluatorReferences(CopyContext context)
        {
            m_vectorEvaluator = context.UpdateReference(m_vectorEvaluator);
        }

        // The Clone method should call the copy constructor.
        public override object Clone(CopyContext context)
        {
            return new Evaluator(this, context);
        }

        // This method determines if there is data available from this Evaluator at
        // the specified date.
        public override bool IsAvailable(JulianDate date)
        {
            // This evaluator is available whenever the nested evaluator is available.
            return m_vectorEvaluator.IsAvailable(date);
        }

        // This method returns a collection of time intervals when data is
        // available from this Evaluator.
        public override TimeIntervalCollection GetAvailabilityIntervals(TimeIntervalCollection consideredIntervals)
        {
            // This evaluator is available whenever the nested evaluator is available.
            return m_vectorEvaluator.GetAvailabilityIntervals(consideredIntervals);
        }

        // This property determines if this Evaluator can safely be used from multiple threads
        // simultaneously. If the evaluator stores data during the Evaluate call, it is not thread
        // safe. Otherwise, it generally is thread safe as long as any nested evaluators it uses
        // are thread safe.
        public override bool IsThreadSafe
        {
            get
            {
                // This evaluator is thread safe as long as the nested evaluator is thread safe.
                return m_vectorEvaluator.IsThreadSafe;
            }
        }

        // This property determines if this Evaluator result changes depending on the time at which it is evaluated.
        public override bool IsTimeVarying
        {
            get { return m_vectorEvaluator.IsTimeVarying; }
        }

        // This property expresses the Axes that this Vector is defined in
        // for various intervals.
        public override TimeIntervalCollection<Axes> DefinedInIntervals
        {
            get
            {
                // This point is defined in the same axes that the nested evaluator is defined in.
                return m_vectorEvaluator.DefinedInIntervals;
            }
        }

        // This is where we do the actual evaluation when only the value of the vector (not additional derivatives)
        // is required.
        public override Cartesian Evaluate(JulianDate date)
        {
            Cartesian value = m_vectorEvaluator.Evaluate(date);
            return value.Invert();
        }

        // This is where we do the actual evaluation when additional derivatives of the vector
        // are requested as well.
        public override Motion<Cartesian> Evaluate(JulianDate date, int order)
        {
            Motion<Cartesian> motion = m_vectorEvaluator.Evaluate(date, order);

            // Note that the motion returned from the evaluator may not have all of the
            // derivatives that were requested.
            Cartesian[] result = new Cartesian[motion.Order + 1];
            for (int i = 0; i <= motion.Order; ++i)
            {
                result[i] = motion[i].Invert();
            }
            return new Motion<Cartesian>(result);
        }

        // Override the Dispose method to call the Dispose() method on any nested
        // evaluators or other disposable nested types.
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                m_vectorEvaluator.Dispose();
            }
        }

        private VectorEvaluator m_vectorEvaluator;
    }
}
See Also
Inheritance Hierarchy
SystemObject
  AGI.Foundation.InfrastructureDefinitionalObject
    AGI.Foundation.GeometryVector
      AGI.Foundation.CelestialMagneticFieldVector
      AGI.Foundation.GeometryParameterizedOnStateVector
      AGI.Foundation.GeometryParameterizedVector
      AGI.Foundation.GeometryVectorAcceleration
      AGI.Foundation.GeometryVectorAngularAcceleration
      AGI.Foundation.GeometryVectorAngularVelocity
      AGI.Foundation.GeometryVectorBPlane
      AGI.Foundation.GeometryVectorCrossProduct
      AGI.Foundation.GeometryVectorDerivative
      AGI.Foundation.GeometryVectorDifferentiator
      AGI.Foundation.GeometryVectorDisplacement
      AGI.Foundation.GeometryVectorEllipsoidSurfaceNormal
      AGI.Foundation.GeometryVectorFixed
      AGI.Foundation.GeometryVectorFixedAtJulianDate
      AGI.Foundation.GeometryVectorInAxes
      AGI.Foundation.GeometryVectorInPointsAxes
      AGI.Foundation.GeometryVectorInterpolator
      AGI.Foundation.GeometryVectorInVectorsAxes
      AGI.Foundation.GeometryVectorInverted
      AGI.Foundation.GeometryVectorNormalized
      AGI.Foundation.GeometryVectorPropagationParameter
      AGI.Foundation.GeometryVectorScaled
      AGI.Foundation.GeometryVectorSum
      AGI.Foundation.GeometryVectorVelocity