Пример #1
0
        static void Main(string[] args)
        {
            // 1. Creating data set
            var dataSet = new CheetahDataSet();

            // 2. Creating geometry
            var line1 = new CheetahLine2D(13, 20, 10, 12);
            var line2 = new CheetahLine2D(8, 10, 20, 9);

            // 3. Creating constraints (put end point of line1 on line2)
            dataSet.AddPointOnCurve(line1, IdentifiableValueReferences.LineEnd, line2);

            // 4. Creating solver object
            var solver = new SolverCpu10();

            // 5. First we evaluate the system the way as we just have added new constraint
            var resultGeometry = EvaluationOnTheFirstApplicationOfConstraint(solver, dataSet);

            // 6. Applying the solution to data set
            var resultLine1 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line1.Id);
            var resultLine2 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line2.Id);

            line1.FillData(resultLine1);
            line2.FillData(resultLine2);

            // 7. Just to check, we don't need to do it all the time, because if parametric.
            // If Evaluate returned true then the problem is solved correctly
            if (!IsPointOnLine(line1.End, line2))
            {
                throw new Exception("Something goes wrong");
            }

            // 8. Now we are simulating drag
            resultGeometry = EvaluationOnDragginTheLine(solver, dataSet, line1, line1.End);

            // 9. Applying the solution to data set
            resultLine1 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line1.Id);
            resultLine2 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line2.Id);

            line1.FillData(resultLine1);
            line2.FillData(resultLine2);

            // 10. Just to check again
            if (!IsPointOnLine(line1.End, line2))
            {
                throw new Exception("Something goes wrong");
            }
        } // Main(...)
Пример #2
0
        static void Main(string[] args)
        {
            // 1. Creating data set
            var dataSet = new CheetahDataSet();

            // 2. Creating geometry
            var line1 = new CheetahLine2D(13, 20, 10, 12);
            var line2 = new CheetahLine2D(8, 10, 20, 9);

            // 3. Creating constraints (put end point of line1 on line2)
            dataSet.AddPointOnCurve(line1, IdentifiableValueReferences.LineEnd, line2);

            // 4. Creating solver object
            var solver = new SolverCpu10();

            // 5. First we evaluate the system the way as we just have added new constraint
            var resultGeometry = EvaluationOnTheFirstApplicationOfConstraint(solver, dataSet);

            // 6. Applying the solution to data set
            var resultLine1 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line1.Id);
            var resultLine2 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line2.Id);
            
            line1.FillData(resultLine1);
            line2.FillData(resultLine2);

            // 7. Just to check, we don't need to do it all the time, because if parametric.
            // If Evaluate returned true then the problem is solved correctly
            if (!IsPointOnLine(line1.End, line2))
                throw new Exception("Something goes wrong");

            // 8. Now we are simulating drag
            resultGeometry = EvaluationOnDragginTheLine(solver, dataSet, line1, line1.End);

            // 9. Applying the solution to data set
            resultLine1 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line1.Id);
            resultLine2 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line2.Id);
            
            line1.FillData(resultLine1);
            line2.FillData(resultLine2);

            // 10. Just to check again
            if (!IsPointOnLine(line1.End, line2))
                throw new Exception("Something goes wrong");
                
        } // Main(...)
Пример #3
0
        static void Main(string[] args)
        {
            // 1. Creating geometric model

            var dataSet = new CheetahDataSet();

            var entIdList = new List <long>();

            CreateGeometricModel(dataSet, entIdList);

            // 2. Creating solver object
            var solver = new SolverCpu10();

            // 3. Creating parametric object and setting tolerance (by default 1E-12)
            var parametric = new CheetahParametricBasic(() => solver, false);

            const double precision = 1E-15; // Working with much better accuracy then the default 1E-12

            CheetahParametricBasic.Settings.Precision = precision;

            // 4. Initializing parametric object using data set
            if (!parametric.Init(dataSet, null, null))
            {
                throw new Exception("Something goes wrong");
            }

            // 5. Running constraints solver
            if (!parametric.Evaluate())
            {
                throw new Exception("Something goes wrong");
            }

            // 6. Retrieving results (we created rectangle with fillets that is "closest" to the initial lines and arcs)
            var resultGeometry = parametric.GetSolution(true);

            // 7. Checking that all geometric constraints are satisfied.
            //    Actually, we have no need to check - if Evaluate returns true than everything is OK
            if (!CheckResults(resultGeometry, entIdList, precision))
            {
                throw new Exception("Something goes wrong");
            }

            GC.Collect();
        } // Main(...)
Пример #4
0
        static void Main(string[] args)
        {
            const string filePath = "dataset.xml";

            // 1. Creating entities and constraints (constraints are not satisfied yet)
            var dataSet = CreateDataSet();

            // 2. Saving data set to xml-file
            dataSet.SaveToXml(filePath);

            // 3. Loading data set from xml-file
            var dataSetFromFile = CheetahDataSet.LoadFromXml(filePath);

            // 4. Creating solver object
            var solver = new SolverCpu10();

            // 5. Creating parametric object and setting tolerance (by default 1E-12)
            var parametric = new CheetahParametricBasic(() => solver, false, true, true);

            const double precision = 1E-8; // Working with lower accuracy then default 1E-12

            CheetahParametricBasic.Settings.Precision = precision;

            // 6. Initializing parametric object using data set
            if (!parametric.Init(dataSetFromFile, null, null))
            {
                throw new Exception("Something goes wrong");
            }

            // 7. Regenerating constrained model (running solver)
            if (!parametric.Evaluate())
            {
                throw new Exception("Something goes wrong");
            }

            // 8. Retrieving results (we created rectangle that is "closest" to the initial lines)
            var resultGeometry = parametric.GetSolution(true);

            GC.Collect();
        } // Main(...)
Пример #5
0
        static void Main(string[] args)
        {
            // 1. Creating geometric model

            var dataSet = new CheetahDataSet();

            var entIdList = new List<long>();

            CreateGeometricModel(dataSet, entIdList);

            // 2. Creating solver object
            var solver = new SolverCpu10();

            // 3. Creating parametric object and setting tolerance (by default 1E-12)
            var parametric = new CheetahParametricBasic(() => solver, false);

            const double precision = 1E-15; // Working with much better accuracy then the default 1E-12 

            CheetahParametricBasic.Settings.Precision = precision;

            // 4. Initializing parametric object using data set
            if (!parametric.Init(dataSet, null, null))
                throw new Exception("Something goes wrong");

            // 5. Running constraints solver
            if (!parametric.Evaluate())
                throw new Exception("Something goes wrong");

            // 6. Retrieving results (we created rectangle with fillets that is "closest" to the initial lines and arcs)
            var resultGeometry = parametric.GetSolution(true);

            // 7. Checking that all geometric constraints are satisfied.
            //    Actually, we have no need to check - if Evaluate returns true than everything is OK
            if (!CheckResults(resultGeometry, entIdList, precision))
                throw new Exception("Something goes wrong");

            GC.Collect();
            
        } // Main(...)
Пример #6
0
        static void Main(string[] args)
        {
            const string filePath = "dataset.xml";

            // 1. Creating entities and constraints (constraints are not satisfied yet)
            var dataSet = CreateDataSet();

            // 2. Saving data set to xml-file
            dataSet.SaveToXml(filePath);

            // 3. Loading data set from xml-file
            var dataSetFromFile = CheetahDataSet.LoadFromXml(filePath);

            // 4. Creating solver object
            var solver = new SolverCpu10();

            // 5. Creating parametric object and setting tolerance (by default 1E-12)
            var parametric = new CheetahParametricBasic(() => solver, false, true, true);

            const double precision = 1E-8; // Working with lower accuracy then default 1E-12 

            CheetahParametricBasic.Settings.Precision = precision;

            // 6. Initializing parametric object using data set
            if (!parametric.Init(dataSetFromFile, null, null))
                throw new Exception("Something goes wrong");

            // 7. Regenerating constrained model (running solver)
            if (!parametric.Evaluate())
                throw new Exception("Something goes wrong");

            // 8. Retrieving results (we created rectangle that is "closest" to the initial lines)
            var resultGeometry = parametric.GetSolution(true);

            GC.Collect();

        } // Main(...)
Пример #7
0
        static void Main(string[] args)
        {
            // 1. Creating data set
            var dataSet = new CheetahDataSet();

            // 2. Creating geometry
            var line1 = new CheetahLine2D(0, 0, 10, 1);
            var line2 = new CheetahLine2D(10, 0, 10, 11);
            var line3 = new CheetahLine2D(10, 10, 1, 10);
            var line4 = new CheetahLine2D(0, 10, 1, 1);

            // 3. Creating constraints
            dataSet.AddCoincidence(line1, IdentifiableValueReferences.LineEnd,
                                   line2, IdentifiableValueReferences.LineStart);

            dataSet.AddCoincidence(line2, IdentifiableValueReferences.LineEnd,
                                   line3, IdentifiableValueReferences.LineStart);

            dataSet.AddCoincidence(line3, IdentifiableValueReferences.LineEnd,
                                   line4, IdentifiableValueReferences.LineStart);

            dataSet.AddCoincidence(line4, IdentifiableValueReferences.LineEnd,
                                   line1, IdentifiableValueReferences.LineStart);

            dataSet.AddPerpendicular(line1, line2);
            dataSet.AddPerpendicular(line2, line3);

            dataSet.AddParallel(line2, line4);

            // 4. Creating solver object
            var solver = new SolverCpu10();

            // 5. Creating parametric object and setting tolerance (by default 1E-12)
            var parametric = new CheetahParametricBasic(() => solver, false, true, true);

            const double precision = 1E-14; // Working with better accuracy then default 1E-12

            CheetahParametricBasic.Settings.Precision = precision;

            // 6. Initializing parametric object using data set
            if (!parametric.Init(dataSet, null, null))
            {
                throw new Exception("Something goes wrong");
            }

            // 7. Regenerating constrained model (running solver)
            if (!parametric.Evaluate())
            {
                throw new Exception("Something goes wrong");
            }

            // 8. Retrieving results (we created rectangle that is "closest" to the initial lines)
            var resultGeometry = parametric.GetSolution(true);

            // 9. We can find corresponding objects by id
            var resultLine1 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line1.Id);
            var resultLine2 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line2.Id);
            var resultLine3 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line3.Id);
            var resultLine4 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line4.Id);

            // 10. Now we can check that all constraints are satisfied (line segments form rectangle)

            if (Math.Abs(resultLine1.End.X - resultLine2.Start.X) > precision || Math.Abs(resultLine1.End.Y - resultLine2.Start.Y) > precision)
            {
                throw new Exception("Something goes wrong");
            }
            if (Math.Abs(resultLine2.End.X - resultLine3.Start.X) > precision || Math.Abs(resultLine2.End.Y - resultLine3.Start.Y) > precision)
            {
                throw new Exception("Something goes wrong");
            }
            if (Math.Abs(resultLine3.End.X - resultLine4.Start.X) > precision || Math.Abs(resultLine3.End.Y - resultLine4.Start.Y) > precision)
            {
                throw new Exception("Something goes wrong");
            }
            if (Math.Abs(resultLine4.End.X - resultLine1.Start.X) > precision || Math.Abs(resultLine4.End.Y - resultLine1.Start.Y) > precision)
            {
                throw new Exception("Something goes wrong");
            }

            if (!IsDivisible(resultLine1.PolarAngle - resultLine2.PolarAngle, Math.PI / 2, precision))
            {
                throw new Exception("Something goes wrong");
            }
            if (!IsDivisible(resultLine2.PolarAngle - resultLine3.PolarAngle, Math.PI / 2, precision))
            {
                throw new Exception("Something goes wrong");
            }

            if (!IsDivisible(resultLine2.PolarAngle - resultLine4.PolarAngle, Math.PI, precision))
            {
                throw new Exception("Something goes wrong");
            }

            GC.Collect();
        } // Main(...)
Пример #8
0
        static void Main(string[] args)
        {
            // 1. Creating data set
            var dataSet = new CheetahDataSet();

            // 2. Creating geometry
            var line1 = new CheetahLine2D(0, 0, 10, 1);
            var line2 = new CheetahLine2D(10, 0, 10, 11);
            var line3 = new CheetahLine2D(10, 10, 1, 10);
            var line4 = new CheetahLine2D(0, 10, 1, 1);

            // 3. Creating constraints
            dataSet.AddCoincidence(line1, IdentifiableValueReferences.LineEnd,
                line2, IdentifiableValueReferences.LineStart);

            dataSet.AddCoincidence(line2, IdentifiableValueReferences.LineEnd,
                line3, IdentifiableValueReferences.LineStart);

            dataSet.AddCoincidence(line3, IdentifiableValueReferences.LineEnd,
                line4, IdentifiableValueReferences.LineStart);

            dataSet.AddCoincidence(line4, IdentifiableValueReferences.LineEnd,
                line1, IdentifiableValueReferences.LineStart);

            dataSet.AddPerpendicular(line1, line2);
            dataSet.AddPerpendicular(line2, line3);

            dataSet.AddParallel(line2, line4);

            // 4. Creating solver object
            var solver = new SolverCpu10();

            // 5. Creating parametric object and setting tolerance (by default 1E-12)
            var parametric = new CheetahParametricBasic(() => solver, false, true, true);

            const double precision = 1E-14; // Working with better accuracy then default 1E-12

            CheetahParametricBasic.Settings.Precision = precision;

            // 6. Initializing parametric object using data set
            if (!parametric.Init(dataSet, null, null))
                throw new Exception("Something goes wrong");

            // 7. Regenerating constrained model (running solver)
            if (!parametric.Evaluate())
                throw new Exception("Something goes wrong");

            // 8. Retrieving results (we created rectangle that is "closest" to the initial lines)
            var resultGeometry = parametric.GetSolution(true);

            // 9. We can find corresponding objects by id
            var resultLine1 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line1.Id);
            var resultLine2 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line2.Id);
            var resultLine3 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line3.Id);
            var resultLine4 = (CheetahLine2D)resultGeometry.Single(x => x.Id == line4.Id);

            // 10. Now we can check that all constraints are satisfied (line segments form rectangle)

            if (Math.Abs(resultLine1.End.X - resultLine2.Start.X) > precision || Math.Abs(resultLine1.End.Y - resultLine2.Start.Y) > precision)
                throw new Exception("Something goes wrong");
            if (Math.Abs(resultLine2.End.X - resultLine3.Start.X) > precision || Math.Abs(resultLine2.End.Y - resultLine3.Start.Y) > precision)
                throw new Exception("Something goes wrong");
            if (Math.Abs(resultLine3.End.X - resultLine4.Start.X) > precision || Math.Abs(resultLine3.End.Y - resultLine4.Start.Y) > precision)
                throw new Exception("Something goes wrong");
            if (Math.Abs(resultLine4.End.X - resultLine1.Start.X) > precision || Math.Abs(resultLine4.End.Y - resultLine1.Start.Y) > precision)
                throw new Exception("Something goes wrong");

            if (!IsDivisible(resultLine1.PolarAngle - resultLine2.PolarAngle, Math.PI / 2, precision))
                throw new Exception("Something goes wrong");
            if (!IsDivisible(resultLine2.PolarAngle - resultLine3.PolarAngle, Math.PI / 2, precision))
                throw new Exception("Something goes wrong");

            if (!IsDivisible(resultLine2.PolarAngle - resultLine4.PolarAngle, Math.PI, precision))
                throw new Exception("Something goes wrong");

            GC.Collect();

        } // Main(...)