コード例 #1
0
    private static void test005()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST005 tests TETRAHEDRON_BARYCENTRIC.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    01 August 2009
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int       test1;
        const int test1_num = 3;
        const int test2_num = 5;

        int seed = 123456789;

        Console.WriteLine("");
        Console.WriteLine("TEST005");
        Console.WriteLine("  TETRAHEDRON_BARYCENTRIC computes the barycentric");
        Console.WriteLine("  coordinates of a point.");
        //
        //  Choose a random tetrahedron.
        //
        for (test1 = 1; test1 <= test1_num; test1++)
        {
            double[] tet_xyz = UniformRNG.r8mat_uniform_01_new(3, 4, ref seed);

            typeMethods.r8mat_transpose_print(3, 4, tet_xyz, "  Random tetrahedron:");
            //
            //  Choose barycentric coordinates C1 at random.
            //
            //  Define a point P.
            //
            //  Have TETRAHEDRON_BARYCENTRIC compute C2, the barycentric coordinates of P.
            //
            int test2;
            for (test2 = 1; test2 <= test2_num; test2++)
            {
                double[] c1     = UniformRNG.r8vec_uniform_01_new(4, ref seed);
                double   c1_sum = typeMethods.r8vec_sum(4, c1);
                int      i;
                for (i = 0; i < 4; i++)
                {
                    c1[i] /= c1_sum;
                }

                double[] p = typeMethods.r8mat_mv_new(3, 4, tet_xyz, c1);

                double[] c2 = Tetrahedron.tetrahedron_barycentric(tet_xyz, p);

                Console.WriteLine("");
                string cout = "  C1 = ";
                for (i = 0; i < 4; i++)
                {
                    cout += "  " + c1[i].ToString("0.######").PadLeft(14);
                }

                Console.WriteLine(cout);
                cout = "  C2 = ";
                for (i = 0; i < 4; i++)
                {
                    cout += "  " + c2[i].ToString("0.######").PadLeft(14);
                }

                Console.WriteLine(cout);
            }
        }
    }
コード例 #2
0
    private static void test007()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST007 tests TET_MESH_SEARCH_NAIVE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    19 August 2009
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int face     = 0;
        int node_num = 0;

        double[]  p        = new double[3];
        int       step_num = 0;
        int       test;
        const int test_num  = 5;
        int       tet_num   = 0;
        const int tet_order = 4;

        double[] tet_xyz = new double[3 * 4];

        int seed = 123456789;

        Console.WriteLine("");
        Console.WriteLine("TEST007");
        Console.WriteLine("  TET_MESH_SEARCH_NAIVE uses a naive algorithm");
        Console.WriteLine("  to search a tetrahedral mesh for the tetrahedron");
        Console.WriteLine("  containing a point.");
        //
        //  Set up the example tetrahedron mesh.
        //
        TetMesh.tet_mesh_order4_example_size(ref node_num, ref tet_num);

        Console.WriteLine("");
        Console.WriteLine("  This mesh has tetrahedron order " + tet_order + "");
        Console.WriteLine("  The number of tetrahedrons is   " + tet_num + "");

        double[] node_xyz = new double[3 * node_num];
        int[]    tet_node = new int[tet_order * tet_num];

        TetMesh.tet_mesh_order4_example_set(node_num, tet_num, ref node_xyz, ref tet_node);
        //
        //  The TET_NEIGHBOR array is needed for the Delaunay search.
        //
        int[] tet_neighbor = TetMesh.tet_mesh_neighbor_tets(tet_order, tet_num, tet_node);

        for (test = 1; test <= test_num; test++)
        {
            //
            //  Choose a tetrahedron at random.
            //
            int tet1 = UniformRNG.i4_uniform_ab(0, tet_num - 1, ref seed);

            Console.WriteLine("");
            Console.WriteLine("  Point was chosen from tetrahedron    " + tet1.ToString(CultureInfo.InvariantCulture).PadLeft(8) + "");

            int j;
            for (j = 0; j < 4; j++)
            {
                int k = tet_node[j + tet1 * 4];
                int i;
                for (i = 0; i < 3; i++)
                {
                    tet_xyz[i + j * 3] = node_xyz[i + k * 3];
                }
            }

            //
            //  Choose a point in the tetrahedron at random.
            //
            Tetrahedron.tetrahedron_sample(tet_xyz, 1, ref seed, ref p);
            //
            //  Naive search.
            //
            int tet2 = TetMesh.tet_mesh_search_naive(node_num, node_xyz, tet_order, tet_num,
                                                     tet_node, p, ref step_num);

            Console.WriteLine("  Naive search ended in tetrahedron    " + tet2.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                              + ", number of steps = " + step_num + "");
            //
            //  Delaunay search.
            //
            int tet3 = TetMesh.tet_mesh_search_delaunay(node_num, node_xyz, tet_order,
                                                        tet_num, tet_node, tet_neighbor, p, ref face, ref step_num);

            Console.WriteLine("  Delaunay search ended in tetrahedron " + tet3.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                              + ", number of steps = " + step_num + "");
        }
    }
コード例 #3
0
    private static void test002()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST002 tests TETRAHEDRON_ORDER4_PHYSICAL_TO_REFERENCE,
    //    TETRAHEDRON_ORDER4_REFERENCE_TO_PHYSICAL.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    08 December 2006
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int N = 10;

        int j;

        double[] phy  = new double[3 * N];
        double[] ref_ = new double[3 * N];
        double[] ref2 = new double[3 * N];
        double[] t    =
        {
            5.0, 0.0, 0.0,
            8.0, 0.0, 0.0,
            5.0, 2.0, 0.0,
            6.0, 1.0, 2.0
        };

        int seed = 123456789;

        Console.WriteLine("");
        Console.WriteLine("TEST002");
        Console.WriteLine("  For an order 4 tetrahedron,");
        Console.WriteLine("  TETRAHEDRON_ORDER4_PHYSICAL_TO_REFERENCE");
        Console.WriteLine("  maps a physical point to a reference point.");
        Console.WriteLine("  TETRAHEDRON_ORDER4_REFERENCE_TO_PHYSICAL ");
        Console.WriteLine("  maps a reference point to a physical point.");
        Console.WriteLine("");
        Console.WriteLine("     ( R, S, T )          ==>  ( X, Y, Z )           ==> ( R2, S2, T2 )");
        Console.WriteLine("");

        Tetrahedron.tetrahedron_reference_sample(N, ref seed, ref ref_);

        Tetrahedron.tetrahedron_order4_reference_to_physical(t, N, ref_, ref phy);
        Tetrahedron.tetrahedron_order4_physical_to_reference(t, N, phy, ref ref2);

        for (j = 0; j < N; j++)
        {
            Console.WriteLine("  " + ref_[0 + j * 3].ToString("0.####").PadLeft(8)
                              + "  " + ref_[1 + j * 3].ToString("0.####").PadLeft(8)
                              + "  " + ref_[2 + j * 3].ToString("0.####").PadLeft(8)
                              + "  "
                              + "  " + phy[0 + j * 3].ToString("0.####").PadLeft(8)
                              + "  " + phy[1 + j * 3].ToString("0.####").PadLeft(8)
                              + "  " + phy[2 + j * 3].ToString("0.####").PadLeft(8)
                              + "  "
                              + "  " + ref2[0 + j * 3].ToString("0.####").PadLeft(8)
                              + "  " + ref2[1 + j * 3].ToString("0.####").PadLeft(8)
                              + "  " + ref2[2 + j * 3].ToString("0.####").PadLeft(8) + "");
        }
    }