示例#1
0
        /// <summary>
        /// Indicates whether this instance and a specified other <see cref="CoordinateVector" /> are equal.
        /// </summary>
        /// <param name="another">Another <see cref="CoordinateVector" /> to compare to.</param>
        /// <returns><c>true</c> if <paramref name="another" /> and this instance represent the same value; otherwise, <c>false</c>.</returns>
        public Boolean Equals(CoordinateVector another)
        {
            if (ReferenceEquals(this, another))
            {
                return(true);
            }

            return(_x == another.X && _y == another.Y && _z == another.Z);
        }
示例#2
0
        /// <summary>
        /// Determines whether the two <see cref="CoordinateVector" /> instances are perpendicular.
        /// </summary>
        /// <param name="first">The first vector.</param>
        /// <param name="second">The second vector.</param>
        /// <param name="precision">The precision model.</param>
        /// <returns><c>true</c> if the two <see cref="CoordinateVector" /> instances are perpendicular; otherwise <c>false</c>.</returns>
        public static Boolean IsPerpendicular(CoordinateVector first, CoordinateVector second, PrecisionModel precision)
        {
            if (precision == null)
            {
                precision = PrecisionModel.Default;
            }

            return(first._x * second._x + first._y * second._y + first._z * second._z <= precision.Tolerance(first, second));
        }
示例#3
0
        /// <summary>
        /// Determines whether the two <see cref="CoordinateVector" /> instances are parallel.
        /// </summary>
        /// <param name="first">The first vector.</param>
        /// <param name="second">The second vector.</param>
        /// <param name="precision">The precision model.</param>
        /// <returns><c>true</c> if the two <see cref="CoordinateVector" /> instances are parallel; otherwise <c>false</c>.</returns>
        public static Boolean IsParallel(CoordinateVector first, CoordinateVector second, PrecisionModel precision)
        {
            if (precision == null)
            {
                precision = PrecisionModel.Default;
            }

            return(Math.Abs(first._x * second._y - first._y * second._x) <= precision.Tolerance(first, second) &&
                   Math.Abs(first._x * second._z - first._z * second._z) <= precision.Tolerance(first, second));
        }
示例#4
0
        /// <summary>
        /// Indicates whether this instance and a specified other <see cref="CoordinateVector" /> are equal.
        /// </summary>
        /// <param name="obj">Another <see cref="CoordinateVector" /> to compare to.</param>
        /// <returns><c>true</c> if <paramref name="another" /> and this instance represent the same value; otherwise, <c>false</c>.</returns>
        public Boolean Equals(CoordinateVector another)
        {
            if (ReferenceEquals(null, another))
            {
                return(false);
            }
            if (ReferenceEquals(this, another))
            {
                return(true);
            }

            return(_x == another._x && _y == another._y && _z == another._z);
        }
示例#5
0
        /// <summary>
        /// Rounds the specified coordinate vector to match the precision model.
        /// </summary>
        /// <param name="vector">The coordinate vector.</param>
        /// <returns>The precise coordinate vector.</returns>
        public CoordinateVector MakePrecise(CoordinateVector vector)
        {
            switch (ModelType)
            {
            case PrecisionModelType.FloatingSingle:
                return(new CoordinateVector((Single)vector.X, (Single)vector.Y, (Single)vector.Z));

            case PrecisionModelType.Fixed:
                return(new CoordinateVector(Math.Floor((vector.X * Scale) + 0.5) / Scale,
                                            Math.Floor((vector.Y * Scale) + 0.5) / Scale,
                                            Math.Floor((vector.Z * Scale) + 0.5) / Scale));

            default:
                return(vector);
            }
        }
示例#6
0
 /// <summary>
 /// Computes the cross product of two <see cref="CoordinateVector" /> instances.
 /// </summary>
 /// <param name="first">The first vector.</param>
 /// <param name="second">The second vector.</param>
 /// <returns>The cross product of two <see cref="CoordinateVector" /> instances.</returns>
 public static CoordinateVector CrossProduct(CoordinateVector first, CoordinateVector second)
 {
     return(new CoordinateVector(first._y * second._z - first._z * second._y, first._z * second._x - first._x * second._z, first._x * second._y - first._y * second._x));
 }
示例#7
0
 /// <summary>
 /// Computes the perp product of two <see cref="CoordinateVector" /> instances.
 /// </summary>
 /// <param name="first">The first vector.</param>
 /// <param name="second">The second vector.</param>
 /// <returns>The perp product of two <see cref="CoordinateVector" /> instances.</returns>
 public static Double PerpProduct(CoordinateVector first, CoordinateVector second)
 {
     return(first._x * second._y - first._y * second._x);
 }
示例#8
0
 /// <summary>
 /// Computes the dot product of two vectors.
 /// </summary>
 /// <param name="first">The first vector.</param>
 /// <param name="second">The second vector.</param>
 /// <returns>The dot product of two vectors.</returns>
 public static Double DotProduct(CoordinateVector first, CoordinateVector second)
 {
     return(first._x * second._x + first._y * second._y + first._z * second._z);
 }
示例#9
0
 /// <summary>
 /// Computes the distance between two <see cref="CoordinateVector" /> instances.
 /// </summary>
 /// <param name="first">The first vector.</param>
 /// <param name="second">The second vector.</param>
 /// <returns>The distance between the two <see cref="CoordinateVector" /> instances.</returns>
 public static Double Distance(CoordinateVector first, CoordinateVector second)
 {
     return(Math.Sqrt(Calculator.Pow(first._x - second._x, 2) + Calculator.Pow(first._y - second._y, 2) + Calculator.Pow(first._z - second._z, 2)));
 }
示例#10
0
 /// <summary>
 /// Determines whether the two <see cref="CoordinateVector" /> instances are perpendicular.
 /// </summary>
 /// <param name="first">The first vector.</param>
 /// <param name="second">The second vector.</param>
 /// <returns><c>true</c> if the two <see cref="CoordinateVector" /> instances are perpendicular; otherwise <c>false</c>.</returns>
 public static Boolean IsPerpendicular(CoordinateVector first, CoordinateVector second)
 {
     return(IsPerpendicular(first, second, PrecisionModel.Default));
 }
示例#11
0
 /// <summary>
 /// Determines whether the two <see cref="CoordinateVector" /> instances are parallel.
 /// </summary>
 /// <param name="first">The first vector.</param>
 /// <param name="second">The second vector.</param>
 /// <returns><c>true</c> if the two <see cref="CoordinateVector" /> instances are parallel; otherwise <c>false</c>.</returns>
 public static Boolean IsParallel(CoordinateVector first, CoordinateVector second)
 {
     return(IsParallel(first, second, PrecisionModel.Default));
 }
示例#12
0
        /// <summary>
        /// Creates a raster mapper from the transformation.
        /// </summary>
        /// <param name="mode">The raster mapping mode.</param>
        /// <param name="translation">The translation coordinate.</param>
        /// <param name="scale">The scale vector.</param>
        /// <returns>The raster mapper based on the specified transformation.</returns>
        /// <exception cref="System.ArgumentException">
        /// The translation is invalid.
        /// or
        /// The scale is invalid.
        /// or
        /// The scale of the X dimension is equal to 0.
        /// or
        /// The scale of the Y dimension is equal to 0.
        /// </exception>
        public static RasterMapper FromTransformation(RasterMapMode mode, Coordinate translation, CoordinateVector scale)
        {
            if (!translation.IsValid)
            {
                throw new ArgumentException("The translation is invalid.", "translation");
            }
            if (!scale.IsValid)
            {
                throw new ArgumentException("The scale is invalid.", "scale");
            }
            if (scale.X == 0)
            {
                throw new ArgumentException("The scale of the X dimension is equal to 0.", "scale");
            }
            if (scale.Y == 0)
            {
                throw new ArgumentException("The scale of the Y dimension is equal to 0.", "scale");
            }

            Matrix transformation = new Matrix(4, 4);

            transformation[0, 0] = scale.X;
            transformation[1, 1] = scale.Y;
            transformation[2, 2] = scale.Z;
            transformation[0, 3] = translation.X;
            transformation[1, 3] = translation.Y;
            transformation[2, 3] = translation.Z;
            transformation[3, 3] = 1;

            return(new RasterMapper(mode, transformation));
        }
示例#13
0
 /// <summary>
 /// Determines whether the specified coordinate vectors are equal.
 /// </summary>
 /// <param name="first">The first coordinate vector.</param>
 /// <param name="second">The second coordinate vector.</param>
 /// <returns><c>true</c> if the two coordinate vectors are considered equal at the specified precision; otherwise, <c>false</c>.</returns>
 public Boolean AreEqual(CoordinateVector first, CoordinateVector second)
 {
     return(AreEqual(first.X, second.X) && AreEqual(first.Y, second.Y) && AreEqual(first.Z, second.Z));
 }