Vector2D.Dot C# (CSharp) Method

Dot() public static method

public static Dot ( Vector2D, v1, Vector2D, v2 ) : double
v1 Vector2D,
v2 Vector2D,
return double
    public static double Dot(Vector2D v1, Vector2D v2)
    {
        return v1.x * v2.x + v1.y * v2.y;
    }

Usage Example

Example #1
0
        protected bool PointinTriangle(Vector2D A, Vector2D B, Vector2D C, Vector2D P)
        {
            Vector2D v0 = C - A;
            Vector2D v1 = B - A;
            Vector2D v2 = P - A;

            float dot00 = (float)v0.Dot(v0);
            float dot01 = (float)v0.Dot(v1);
            float dot02 = (float)v0.Dot(v2);
            float dot11 = (float)v1.Dot(v1);
            float dot12 = (float)v1.Dot(v2);

            float inverDeno = 1 / (dot00 * dot11 - dot01 * dot01);

            float u = (dot11 * dot02 - dot01 * dot12) * inverDeno;

            if (u < 0 || u > 1) // if u out of range, return directly
            {
                return(false);
            }

            float v = (dot00 * dot12 - dot01 * dot02) * inverDeno;

            if (v < 0 || v > 1) // if v out of range, return directly
            {
                return(false);
            }

            return(u + v <= 1);
        }
All Usage Examples Of Vector2D::Dot