Exemplo n.º 1
0
        public static void Barycentric(Vector a, Vector b, Vector c, Vector p, out float u, out float v, out float w)
        {
            Vector v0 = b - a, v1 = c - a, v2 = p - a;
            float  d00   = (float)JMath.Dot(v0, v0);
            float  d01   = (float)JMath.Dot(v0, v1);
            float  d11   = (float)JMath.Dot(v1, v1);
            float  d20   = (float)JMath.Dot(v2, v0);
            float  d21   = (float)JMath.Dot(v2, v1);
            float  denom = d00 * d11 - d01 * d01;

            v = (d11 * d20 - d01 * d21) / denom;
            w = (d00 * d21 - d01 * d20) / denom;
            u = 1 - v - w;
        }
Exemplo n.º 2
0
        public static bool SegmentTest(Vector a, Vector b, Vector c, Vector d)
        {
            double triaa = JMath.SignedTriangleArea(a, b, d);
            double triab = JMath.SignedTriangleArea(a, b, c);

            if (triaa * triab < 0.0)
            {
                double triac = JMath.SignedTriangleArea(c, d, a);
                double triad = triac + triab - triaa;
                if (triac * triad < 0.0)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 3
0
        public static bool SegmentTest(Vector a, Vector b, Vector c, Vector d, out Vector i)
        {
            double triaa = JMath.SignedTriangleArea(a, b, d);
            double triab = JMath.SignedTriangleArea(a, b, c);

            if (triaa * triab < 0.0)
            {
                double triac = JMath.SignedTriangleArea(c, d, a);
                double triad = triac + triab - triaa;
                if (triac * triad < 0.0)
                {
                    double t = triac / (triac - triad);
                    i = a + (b - a) * t;
                    return(true);
                }
            }
            i = null;
            return(false);
        }
Exemplo n.º 4
0
        public static Vector ClosestPointOnSegment(Vector vA, Vector vB, Vector vPoint)
        {
            Vector VectorA = vPoint - vA;
            Vector diff    = vB - vA;
            float  d       = (float)diff.Length;
            Vector VectorB = diff.Normalize();
            float  t       = (float)JMath.Dot(VectorB, VectorA);

            if (t <= 0)
            {
                return(vA);
            }
            if (t >= d)
            {
                return(vB);
            }

            Vector res = vA + VectorB * t;

            return(res);
        }
Exemplo n.º 5
0
 public static double AngleDeg(Vector va, Vector vb)
 {
     return(JMath.AngleRad(va, vb) / Math.PI * 180.0);
 }
Exemplo n.º 6
0
 /*
  * a*b=|a|*|b|*cos angle
  * cos angle=a*b/(|a|*|b|)
  * angle = arccos (a*b/(|a|*|b|))
  */
 public static double AngleRad(Vector va, Vector vb)
 {
     return(Math.Acos(JMath.Dot(va, vb) / (va.Length + vb.Length)));
 }