예제 #1
0
        private bool IsBetweenTriangles(List <Triangle> triangles, Tetrahedron tetrahedron, Direction direction)
        {
            for (int i = 0; i < triangles.Count; i += 2)
            {
                switch (direction)
                {
                case Direction.X:
                    if (tetrahedron.Center.X >= triangles[i].Center.X && tetrahedron.Center.X <= triangles[i + 1].Center.X)
                    {
                        return(true);
                    }
                    break;

                case Direction.Y:
                    if (tetrahedron.Center.Y >= triangles[i].Center.Y && tetrahedron.Center.Y <= triangles[i + 1].Center.Y)
                    {
                        return(true);
                    }
                    break;

                case Direction.Z:
                    if (tetrahedron.Center.Z >= triangles[i].Center.Z && tetrahedron.Center.Z <= triangles[i + 1].Center.Z)
                    {
                        return(true);
                    }
                    break;

                default:
                    throw new Exception("Wrong direction.");
                }
            }
            return(false);
        }
예제 #2
0
        private List <Tetrahedron> ApplyResultsToTetrahedrons(double[] results)
        {
            List <double>      formax = new List <double>();
            List <Tetrahedron> list   = new List <Tetrahedron>();
            StreamWriter       wt1    = new StreamWriter("test.color");
            double             max1   = 0;

            foreach (var item in model.Tetrahedrons)
            {
                Tetrahedron tmp = new Tetrahedron(item);

                tmp.Nodes.ForEach(n =>
                {
                    n.X       += results[n.GlobalIndex * 3];
                    n.Y       += results[n.GlobalIndex * 3 + 1];
                    n.Z       += results[n.GlobalIndex * 3 + 2];
                    double z   = Math.Abs(solution.Results[n.GlobalIndex * 3 + 2]);
                    n.DefColor = z;
                    formax.Add(z);
                });
                list.Add(tmp);
            }
            max1 = formax.Max();
            wt1.WriteLine($"{max1}");
            wt1.Close();
            return(list);
        }
예제 #3
0
        private bool IsInsideStlArea(List <List <Triangle> > stlModel, Tetrahedron tetrahedron)
        {
            List <Triangle> xy = new List <Triangle>();

            foreach (var ml in stlModel)
            {
                var trngls = ml.Where(trngl => trngl.IsInTriangleXY(tetrahedron.Center))
                             .OrderBy(trngl => trngl.Center.Z).ToList();
                if (trngls.Count % 2 == 0)
                {
                    xy.AddRange(trngls);
                }
            }

            List <Triangle> xz = new List <Triangle>();

            foreach (var ml in stlModel)
            {
                var trngls = ml.Where(trngl => trngl.IsInTriangleXZ(tetrahedron.Center))
                             .OrderBy(trngl => trngl.Center.Y)
                             .ToList();
                if (trngls.Count % 2 == 0)
                {
                    xz.AddRange(trngls);
                }
            }

            List <Triangle> yz = new List <Triangle>();

            foreach (var ml in stlModel)
            {
                var trngls = ml.Where(trngl => trngl.IsInTriangleYZ(tetrahedron.Center))
                             .OrderBy(trngl => trngl.Center.X)
                             .ToList();
                if (trngls.Count % 2 == 0)
                {
                    yz.AddRange(trngls);
                }
            }
            xy.RemoveAll(trngl => trngl is null);
            xz.RemoveAll(trngl => trngl is null);
            yz.RemoveAll(trngl => trngl is null);

            return(IsBetweenTriangles(xy, tetrahedron, Direction.Z) &&
                   IsBetweenTriangles(xz, tetrahedron, Direction.Y) &&
                   IsBetweenTriangles(yz, tetrahedron, Direction.X));
        }
예제 #4
0
파일: Program.cs 프로젝트: dm4t/Assignments
        static void Main(string[] args)
        {
            char input;

            List <Shape> Shapes = new List <Shape>();

            while (true)
            {
                Console.WriteLine("A - Rectangle \n" +
                                  "B - Square \n" +
                                  "C - Box \n" +
                                  "D - Cube \n" +
                                  "E - Ellipse \n" +
                                  "F - Circle \n" +
                                  "G - Cylinder \n" +
                                  "H - Sphere \n" +
                                  "I - Triangle \n" +
                                  "J - Tetrahedron \n " +
                                  "\n0 - List all shapes and Exit      (" + Shapes.Count + " Size)");

                input = Char.Parse(Console.ReadLine());

                switch (input)
                {
                case 'A':
                case 'a':
                    var newRectangle = new Rectangle();
                    newRectangle.SetData();
                    Shapes.Add(newRectangle);
                    break;

                case 'B':
                case 'b':
                    var newSquare = new Square();
                    newSquare.SetData();
                    Shapes.Add(newSquare);
                    break;

                case 'C':
                case 'c':
                    var newBox = new Box();
                    newBox.SetData();
                    Shapes.Add(newBox);
                    break;

                case 'D':
                case 'd':
                    var newCube = new Cube();
                    newCube.SetData();
                    Shapes.Add(newCube);
                    break;

                case 'E':
                case 'e':
                    var newEllipse = new Ellipse();
                    newEllipse.SetData();
                    Shapes.Add(newEllipse);
                    break;

                case 'F':
                case 'f':
                    var newCircle = new Circle();
                    newCircle.SetData();
                    Shapes.Add(newCircle);
                    break;

                case 'G':
                case 'g':
                    var newCylinder = new Cylinder();
                    newCylinder.SetData();
                    Shapes.Add(newCylinder);
                    break;

                case 'H':
                case 'h':
                    var newSphere = new Sphere();
                    newSphere.SetData();
                    Shapes.Add(newSphere);
                    break;

                case 'I':
                case 'i':
                    var newTriangle = new Triangle();
                    newTriangle.SetData();
                    Shapes.Add(newTriangle);

                    break;

                case 'J':
                case 'j':
                    var newTetrahedron = new Tetrahedron();
                    newTetrahedron.SetData();
                    Shapes.Add(newTetrahedron);

                    break;

                case '0':

                    foreach (Shape temp in Shapes)
                    {
                        Console.WriteLine(temp.ToString());
                    }
                    Console.Read();

                    break;
                }



                Console.Clear();
            }
        }