EdgeGraph.Edge.GetPerpendicularTowardsPoint C# (CSharp) Method

GetPerpendicularTowardsPoint() public static method

Return left or right normal for edge, depending on which normal points towards the given point.
public static GetPerpendicularTowardsPoint ( Vector3 v1, Vector3 v2, Vector3 point ) : Vector3
v1 Vector3
v2 Vector3
point Vector3
return Vector3
        public static Vector3 GetPerpendicularTowardsPoint(Vector3 v1, Vector3 v2, Vector3 point)
        {
            //Perpendicular vectors
            Vector3 left = GetLeftPerpendicular(v1, v2);
            Vector3 right = GetRightPerpendicular(v1, v2);

            //Center point of the line
            Vector3 center = (v1 + v2) / 2f;

            //Direction from center to point
            Vector3 toPoint = (point - center).normalized;

            //Dot products
            float dotLeft = Vector3.Dot(left, toPoint);
            float dotRight = Vector3.Dot(right, toPoint);

            //Return perpendicular that is towards the point
            return dotLeft > dotRight ? left : right;
        }