Пример #1
0
        /// <summary>
        /// Returns the distance from the point A of this line to the intersecting perpendicular point relative to a given point.
        /// </summary>
        /// <param name="A"></param>
        /// <param name="B"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public float PerpendicularBase(Vector2 point) {
            // Pythagoras theorem: h2 = a2 + b2
            Vector2 AP = point - PointA;

            float hypotenuse = AP.magnitude;
            float perpendicularDistance = PerpendicularDistance(point);

            float baseIntersectionLength = Mathf.Sqrt(Mathf.Pow(hypotenuse, 2) - Mathf.Pow(perpendicularDistance, 2));
            float sign = Hedra.HardClamp(Vector2.Dot(AP.normalized, Vector.normalized), -1, 1);
            return baseIntersectionLength * sign;
        }