Example #1
0
        private static bool OnSamePlane(vec3 p0, vec3 p1, vec3 p2, List <vec3> result)
        {
            bool samePlane = true;

            vec3  p01 = p1 - p0; vec3 p02 = p2 - p0;
            vec3  direction = p01.cross(p02);
            float A = direction.x, B = direction.y, C = direction.z;
            // A(x - p0.x) + B(y - p0.y) + C(z - p0.z) = 0
            // Ax + By + Cz + D = 0
            float D      = -direction.dot(p0);
            float length = direction.length();

            direction = direction / length;
            D         = D / length;
            {
                float diff = direction.dot(p0) + D;
                Console.WriteLine(diff);
            }
            {
                float diff = direction.dot(p1) + D;
                Console.WriteLine(diff);
            }
            {
                float diff = direction.dot(p2) + D;
                Console.WriteLine(diff);
            }
            for (int i = 0; i < result.Count; i++)
            {
                vec3  p    = new vec3(result[i]);
                float diff = direction.dot(p) + D;
                if (Math.Abs(diff) / direction.length() > 0.01f)
                {
                    //Console.WriteLine("Not same plane!");
                    samePlane = false;
                }
            }

            return(samePlane);
        }
Example #2
0
        private static bool OnSameLine(vec3 p0, vec3 p1, List <vec3> result)
        {
            bool  sameLine = true;
            vec3  p01      = p1 - p0;
            float length   = p01.length();

            foreach (var item in result)
            {
                vec3  other       = item - (p0 + p1) / 2;
                float otherLength = other.length();
                float sum         = Math.Abs(other.dot(p01));
                float diff        = length * otherLength - sum;
                if (diff / sum > 0.01f)
                {
                    sameLine = false;
                }
            }

            return(sameLine);
        }