/// <summary>
 /// Calculates the distance between a point and a solid oriented box.
 /// </summary>
 /// <param name="point">A <see cref="Vector2F"/> instance.</param>
 /// <param name="obb">An <see cref="OrientedBox"/> instance.</param>
 /// <returns>The distance between a point and a solid oriented box.</returns>
 /// <remarks>
 /// Treating the oriented box as solid means that any point inside the box has
 /// distance zero from the box.
 /// </remarks>
 public static float Distance(Vector2F point, OrientedBox obb)
 {
     return (float)System.Math.Sqrt(SquaredDistance(point, obb));
 }
        /// <summary>
        /// Calculates the squared distance between a point and a solid oriented box.
        /// </summary>
        /// <param name="point">A <see cref="Vector2F"/> instance.</param>
        /// <param name="obb">An <see cref="OrientedBox"/> instance.</param>
        /// <param name="closestPoint">The closest point in box coordinates.</param>
        /// <returns>The squared distance between a point and a solid oriented box.</returns>
        /// <remarks>
        /// Treating the oriented box as solid means that any point inside the box has
        /// distance zero from the box.
        /// </remarks>
        public static float SquaredDistancePointSolidOrientedBox(Vector2F point, OrientedBox obb, out Vector2F closestPoint)
        {
            Vector2F diff = point - obb.Center;
            Vector2F closest = new Vector2F(
                Vector2F.Dot(diff, obb.Axis1),
                Vector2F.Dot(diff, obb.Axis2));

            float sqrDist = 0.0f;
            float delta	  = 0.0f;

            if (closest.X < -obb.Extent1)
            {
                delta = closest.X + obb.Extent1;
                sqrDist += delta*delta;
                closest.X = -obb.Extent1;
            }
            else if (closest.X > obb.Extent1)
            {
                delta = closest.X - obb.Extent1;
                sqrDist += delta*delta;
                closest.X = obb.Extent1;
            }

            if (closest.Y < -obb.Extent2)
            {
                delta = closest.Y + obb.Extent2;
                sqrDist += delta*delta;
                closest.Y = -obb.Extent2;
            }
            else if (closest.Y > obb.Extent2)
            {
                delta = closest.Y - obb.Extent2;
                sqrDist += delta*delta;
                closest.Y = obb.Extent2;
            }

            closestPoint = closest;

            return sqrDist;
        }
 /// <summary>
 /// Calculates the squared distance between a point and a solid oriented box.
 /// </summary>
 /// <param name="point">A <see cref="Vector2F"/> instance.</param>
 /// <param name="obb">An <see cref="OrientedBox"/> instance.</param>
 /// <returns>The squared distance between a point and a solid oriented box.</returns>
 /// <remarks>
 /// Treating the oriented box as solid means that any point inside the box has
 /// distance zero from the box.
 /// </remarks>
 public static float SquaredDistance(Vector2F point, OrientedBox obb)
 {
     Vector2F temp;
     return SquaredDistancePointSolidOrientedBox(point, obb, out temp);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="OrientedBox"/> class using given values from another box instance.
        /// </summary>
        /// <param name="box">A <see cref="OrientedBox"/> instance to take values from.</param>
        public OrientedBox(OrientedBox box)
        {
            _center = box.Center;

            _axis1 = box.Axis1;
            _axis2 = box.Axis2;

            _extent1 = box.Extent1;
            _extent2 = box.Extent2;
        }
示例#5
0
 /// <summary>
 /// Calculates the distance between a point and a solid oriented box.
 /// </summary>
 /// <param name="point">A <see cref="Vector2F"/> instance.</param>
 /// <param name="obb">An <see cref="OrientedBox"/> instance.</param>
 /// <returns>The distance between a point and a solid oriented box.</returns>
 /// <remarks>
 /// Treating the oriented box as solid means that any point inside the box has
 /// distance zero from the box.
 /// </remarks>
 public static float Distance(Vector2F point, OrientedBox obb)
 {
     return((float)System.Math.Sqrt(SquaredDistance(point, obb)));
 }
示例#6
0
        /// <summary>
        /// Calculates the squared distance between a point and a solid oriented box.
        /// </summary>
        /// <param name="point">A <see cref="Vector2F"/> instance.</param>
        /// <param name="obb">An <see cref="OrientedBox"/> instance.</param>
        /// <returns>The squared distance between a point and a solid oriented box.</returns>
        /// <remarks>
        /// Treating the oriented box as solid means that any point inside the box has
        /// distance zero from the box.
        /// </remarks>
        public static float SquaredDistance(Vector2F point, OrientedBox obb)
        {
            Vector2F temp;

            return(SquaredDistancePointSolidOrientedBox(point, obb, out temp));
        }