Пример #1
0
        /// <summary>
        /// Assesses whether the ray passess the given point within the specified margin.
        /// </summary>
        /// <param name="raystart"> The origin point of the ray.</param>
        /// <param name="direction"> The direction the ray follows.</param>
        /// <param name="point"> The point being assessed.</param>
        /// <param name="margin"> The margin.</param>
        /// <returns>True if the two vectors are within the same margin of each other or the ray itself passess the point within the margin.</returns>
        public static bool Vector3RayPassesPoint(Vector2 raystart, Vector2 direction, Vector2 point, float margin)
        {
            for (int i = 0; i < 2; i++)
            {
                int   j = i == 0 ? 1 : 0;
                int   z = j == 0 ? (i == 1 ? 2 : 1) : 2;
                float factor;
                if (direction[i] == 0)
                {
                    factor = 0;
                }
                else
                {
                    factor = (point[i] - raystart[i]) / direction[i];
                }

                if (factor < 0)
                {
                    return(false);
                }

                if (Comparisons.WithinMargin((raystart[j] + direction[j] * factor), point[j], margin) && Comparisons.WithinMargin((raystart[z] + direction[z] * factor), point[z], margin))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
        /// <summary>
        /// Assesses whether the specified vector, defined by a direction and any point on the vector, passess the specified point within the margin
        /// </summary>
        /// <param name="anypoint"> Any point along the vector</param>
        /// <param name="direction"> The direction of the vector.</param>
        /// <param name="point"> The point being assessed.</param>
        /// <param name="margin"> The margin</param>
        /// <returns></returns>
        public static bool Vector2PassesPoint(Vector2 anypoint, Vector2 direction, Vector2 point, float margin)
        {
            for (int i = 0; i < 2; i++)
            {
                int   j = i == 0 ? 1 : 0;
                float factor;
                if (direction[i] == 0)
                {
                    factor = 0;
                }
                else
                {
                    factor = (point[i] - anypoint[i]) / direction[i];
                }

                if (Comparisons.WithinMargin((anypoint[j] + direction[j] * factor), point[j], margin))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #3
0
 /// <summary>
 /// Assesses whether the two vectors are within the provided margin of each other. That is, whether their proximity is within the provided margin.
 /// </summary>
 /// <param name="v1">First vector provided</param>
 /// <param name="v2">Second Vector provided</param>
 /// <param name="margin">The margin</param>
 /// <returns>true if the two vectors within each other's margin. False if otherwise</returns>
 public static bool Vector3WithinMargin(Vector3 v1, Vector3 v2, float margin)
 {
     return(Comparisons.WithinMargin(v1.x, v2.x, margin) && Comparisons.WithinMargin(v1.y, v2.y, margin) &&
            Comparisons.WithinMargin(v1.z, v2.z, margin));
 }