コード例 #1
0
        /// <summary>
        /// Indicates whether or not the given shape is contained entirely within this cylinder (no part of the <paramref name="other"/>
        /// shape may be outside this one).
        /// </summary>
        /// <param name="other">The shape to check.</param>
        /// <returns>True if the other shape is completely within this cylinder, false if any part of it
        /// is outside the cylinder.</returns>
        public bool Contains(Cone other)
        {
            float errorMargin = MathUtils.FlopsErrorMargin;
            float halfHeightPlusErrorMargin = Height / 2f + errorMargin;

            return(Vector3.Distance(Center[0, 2], other.TopCenter[0, 2])
                   + Math.Max(other.TopRadius, other.BottomRadius) <= Radius + errorMargin &&
                   Math.Abs(Center.Y - other.TopCenter.Y) <= halfHeightPlusErrorMargin &&
                   Math.Abs(Center.Y - (other.TopCenter.Y - other.Height)) <= halfHeightPlusErrorMargin);
        }
コード例 #2
0
        /// <summary>
        /// Indicates whether or not the given shape is contained entirely within this sphere (no part of the <paramref name="other"/>
        /// shape may be outside this one).
        /// </summary>
        /// <param name="other">The shape to check.</param>
        /// <returns>True if the other shape is completely within this sphere, false if any part of it
        /// is outside the sphere.</returns>
        public bool Contains(Cone other)
        {
            float distanceFromCentreToConeTop    = Math.Abs(other.TopCenter.Y - Center.Y);
            float distanceFromCentreToConeBottom = Math.Abs(Center.Y - (other.TopCenter.Y - other.Height));

            if (distanceFromCentreToConeTop > Radius || distanceFromCentreToConeBottom > Radius)
            {
                return(false);
            }

            float sphereRadiusAtConeTop    = GetRadius(distanceFromCentreToConeTop);
            float sphereRadiusAtConeBottom = GetRadius(distanceFromCentreToConeBottom);

            float xzDistance  = Vector3.Distance(other.TopCenter[0, 2], Center[0, 2]);
            float errorMargin = MathUtils.FlopsErrorMargin;

            return(xzDistance + other.TopRadius <= sphereRadiusAtConeTop + errorMargin &&
                   xzDistance + other.BottomRadius <= sphereRadiusAtConeBottom + errorMargin);
        }
コード例 #3
0
        /// <summary>
        /// Indicates whether or not the given shape is contained entirely within this cuboid (no part of the <paramref name="other"/>
        /// shape may be outside this one).
        /// </summary>
        /// <param name="other">The shape to check.</param>
        /// <returns>True if the other shape is completely within this cuboid, false if any part of it
        /// is outside the cuboid.</returns>
        public bool Contains(Cone other)
        {
            float errorMargin = MathUtils.FlopsErrorMargin;

            if (other.IsConicalFrustum)
            {
                bool topSectionFits =
                    other.TopCenter.X - other.TopRadius + errorMargin >= FrontBottomLeft.X &&
                    other.TopCenter.X + other.TopRadius <= FrontBottomLeft.X + Width + errorMargin &&
                    other.TopCenter.Z - other.TopRadius + errorMargin >= FrontBottomLeft.Z &&
                    other.TopCenter.Z + other.TopRadius + errorMargin <= FrontBottomLeft.Z + Depth + errorMargin;
                if (!topSectionFits)
                {
                    return(false);
                }
            }

            return(other.TopCenter.Y + errorMargin >= FrontBottomLeft.Y &&
                   other.TopCenter.Y + other.Height <= FrontBottomLeft.Y + Height + errorMargin &&
                   other.TopCenter.X - other.BottomRadius + errorMargin >= FrontBottomLeft.X &&
                   other.TopCenter.X + other.BottomRadius <= FrontBottomLeft.X + Width + errorMargin &&
                   other.TopCenter.Z - other.BottomRadius + errorMargin >= FrontBottomLeft.Z &&
                   other.TopCenter.Z + other.BottomRadius <= FrontBottomLeft.Z + Depth + errorMargin);
        }
コード例 #4
0
 /// <summary>
 /// Indicates whether any portion of this cylinder and the <paramref name="other"/> shape overlap.
 /// </summary>
 /// <param name="other">The shape to check against this one.</param>
 /// <returns>True if any part of both shapes overlap, false if they are entirely separate.</returns>
 public bool Intersects(Cone other)
 {
     return(other.Intersects(this));
 }