Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello world");

            var O = new P3D(0, 0, 0);

            var rs = new RandomSphere();
            var p  = new P3D[4];

            int N    = 100000000;
            int nbIn = 0;

            for (int k = 0; k < N; k++)
            {
                for (int i = 0; i < p.Length; i++)
                {
                    p[i] = rs.GenPoint();
                    //Console.WriteLine($"{p[i]} {p[i].N2()}");
                }

                // Centre dans tetrahedre (A, B, C, D) ?
                var b = RandomSphere.isCenterInTetrahedre(p);
                if (b)
                {
                    nbIn++;
                }
            }
            Console.WriteLine($"{nbIn} {N} {(double)nbIn/N}");
        }
Exemplo n.º 2
0
        private static bool IsGoodSide(P3D A, P3D B, P3D C, P3D D, P3D M)
        {
            var n = P3D.CrossProduct(B - A, C - A); // n = AB x AC, normale au plan (A,B,C)
            var d = P3D.ScalarProduct(n, D - A);    // n.AD
            var m = P3D.ScalarProduct(n, M - A);    // n.AM

            return(d * m > 0);                      // si d et m sont de meme signes M et D sont du meme coté
        }
Exemplo n.º 3
0
 public static double ScalarProduct(P3D A, P3D B)
 {
     return(A.x * B.x + A.y * B.y + A.z * B.z);
 }
Exemplo n.º 4
0
 public static P3D CrossProduct(P3D A, P3D B)
 {
     return(new P3D(+A.y * B.z - A.z * B.y, -A.x * B.z + A.z * B.x, +A.x * B.y - A.y * B.x));
 }