Ejemplo n.º 1
0
 private Vector3D EvaluateIntersectionFunction(
     IntersectionParametrisation parametrisation
     )
 {
     return(_surfaces[0].Evaluate(parametrisation.First) -
            _surfaces[1].Evaluate(parametrisation.Second));
 }
Ejemplo n.º 2
0
        private DenseMatrix GetJacobian(
            IntersectionParametrisation parametrisation
            )
        {
            var dfU = _surfaces[0].Derivative(
                parametrisation.First,
                DerivativeParameter.U
                );

            var dfV = _surfaces[0].Derivative(
                parametrisation.First,
                DerivativeParameter.V
                );

            var dgU = -1.0 * _surfaces[1].Derivative(
                parametrisation.Second,
                DerivativeParameter.U
                );

            var dgV = -1.0 * _surfaces[1].Derivative(
                parametrisation.Second,
                DerivativeParameter.V
                );

            return(DenseMatrix.OfArray(new[, ]
            {
                { dfU.X, dfV.X, dgU.X, dgV.X },
                { dfU.Y, dfV.Y, dgU.Y, dgV.Y },
                { dfU.Z, dfV.Z, dgU.Z, dgV.Z },
            }));
        }
Ejemplo n.º 3
0
        private DenseMatrix GetPlaneJacobian(
            IntersectionParametrisation previousParametrisation,
            Vector previousPoint,
            Vector tangentVector
            )
        {
            var planeUDerivative = EvaluateNumericalDerivativeForPlaneEquation(
                _surfaces[0],
                previousParametrisation.First,
                previousPoint,
                tangentVector,
                DerivativeParameter.U
                );

            var planeVDerivative = EvaluateNumericalDerivativeForPlaneEquation(
                _surfaces[0],
                previousParametrisation.First,
                previousPoint,
                tangentVector,
                DerivativeParameter.V
                );

            var planeJacobian = DenseMatrix.OfArray(
                new[, ]
            {
                { planeUDerivative[0], planeVDerivative[0], 0.0, 0.0 },
                { planeUDerivative[1], planeVDerivative[1], 0.0, 0.0 },
                { planeUDerivative[2], planeVDerivative[2], 0.0, 0.0 },
            }
                );

            return(planeJacobian);
        }
Ejemplo n.º 4
0
        private int FindParametrisationIndex(
            IntersectionParametrisation parametrisation
            )
        {
            for (var i = 0; i < Polygon.Count - 10; ++i)
            {
                var norm1 = Parametrisation.DistanceNormMax(
                    parametrisation.First,
                    Polygon[i].First
                    );

                var norm2 = Parametrisation.DistanceNormMax(
                    parametrisation.Second,
                    Polygon[i].Second
                    );

                //IntersectionParametrisation.DistanceNormMax(
                //parametrisation,
                //Polygon[i]
                //);

                if (norm1 < EqualityEpsilon || norm2 < EqualityEpsilon)
                {
                    return(i);
                }
            }

            return(-1);
        }
Ejemplo n.º 5
0
        private bool AreEdgeTrackingBoundaryConditionsFullfilled(
            IntersectionParametrisation?previousParametrisation,
            IntersectionParametrisation?currentIntersectionParametrisation
            )
        {
            if (!(currentIntersectionParametrisation?.IsValid() ?? false))
            {
                return(true);
            }

            if (!previousParametrisation.HasValue)
            {
                return(false);
            }

            Debug.Assert(
                currentIntersectionParametrisation != null,
                "currentIntersectionParametrisation != null"
                );

            if (MinimumStepLength >=
                IntersectionParametrisation.DistanceNormMax(
                    previousParametrisation.Value,
                    currentIntersectionParametrisation.Value
                    ))
            {
                return(true);
            }

            return(false);
        }
 public static double DistanceNormMax(
     IntersectionParametrisation left,
     IntersectionParametrisation right
     )
 {
     return(Math.Max(
                Parametrisation.DistanceNormMax(left.First, right.First),
                Parametrisation.DistanceNormMax(left.Second, right.Second)
                ));
 }
Ejemplo n.º 7
0
        private Vector3D EvaluateTangent(
            IntersectionParametrisation previousParametrisation
            )
        {
            var normal1 = _surfaces[0].Normal(previousParametrisation.First);
            var normal2 = _surfaces[1].Normal(previousParametrisation.Second);
            var tangent = Vector3D.CrossProduct(normal1, normal2);

            tangent.Normalize();
            return(tangent);
        }
Ejemplo n.º 8
0
        private static IntersectionParametrisation EvaluateNewtonStep(
            IntersectionParametrisation previousParametrisation,
            Matrix jacobian,
            Vector evaluatedFunction
            )
        {
            var jacobianInv = GetPseudoInverse(jacobian);
            var correction  = jacobianInv * evaluatedFunction;

            return(previousParametrisation - correction);
        }
Ejemplo n.º 9
0
        private Matrix GetJacobianWithPlane(
            IntersectionParametrisation previousParametrisation,
            Vector previousPoint,
            Vector tangentVector
            )
        {
            var simpleJacobian = GetJacobian(previousParametrisation);
            var planeJacobian  = GetPlaneJacobian(
                previousParametrisation,
                previousPoint,
                tangentVector
                );

            return(simpleJacobian - planeJacobian);
        }
Ejemplo n.º 10
0
        private IntersectionParametrisation EvaluateTwoSurfacesNewtonStep(
            IntersectionParametrisation previousParametrisation
            )
        {
            var evaluatedFunction =
                EvaluateIntersectionFunction(previousParametrisation)
                .ToMathVector();

            var jacobian = GetJacobian(previousParametrisation);

            return(EvaluateNewtonStep(
                       previousParametrisation,
                       jacobian,
                       evaluatedFunction
                       ));
        }
Ejemplo n.º 11
0
        private Vector EvaluateIntersectionWithPlaneFunction(
            IntersectionParametrisation parametrisation,
            Vector previousPoint,
            Vector tangentVector
            )
        {
            var tantentPlaneEquationVector = EvaluatePlaneEquation(
                _surfaces[0],
                parametrisation.First,
                previousPoint,
                tangentVector
                );

            return(EvaluateIntersectionFunction(parametrisation).ToMathVector()
                   - tantentPlaneEquationVector);
        }
Ejemplo n.º 12
0
        public bool FinishIfLoopedBack(
            IntersectionParametrisation parametrisation
            )
        {
            var index = FindParametrisationIndex(parametrisation);

            if (index == -1)
            {
                return(false);
            }

            Polygon = Polygon.Skip(index).ToList();
            Polygon.Add(parametrisation);
            Polygon.Add(Polygon.First());

            IsLooped = true;
            return(true);
        }
Ejemplo n.º 13
0
        private IntersectionParametrisation?GetNextInitialGuess(
            IntersectionParametrisation previousGuess
            )
        {
            var previousPoint = ((Vector3D)_surfaces[0].Evaluate(
                                     previousGuess.First
                                     )).ToMathVector();

            var tangent = EvaluateTangent(previousGuess).ToMathVector();

            var iterationNumber        = 0;
            var currentParametrisation = previousGuess;

            do
            {
                var nextParametrisation = EvaluateNextGuessNewtonStep(
                    currentParametrisation,
                    previousPoint,
                    tangent
                    );

                if (!nextParametrisation.IsValid())
                {
                    return(null);
                }

                if (MinimumStepLength >=
                    IntersectionParametrisation.DistanceNormMax(
                        nextParametrisation,
                        currentParametrisation
                        ))
                {
                    return(nextParametrisation);
                }

                currentParametrisation = nextParametrisation;
            } while (++iterationNumber < MaximumNewtonIterations);

            return(null);
        }
Ejemplo n.º 14
0
        private IntersectionParametrisation?FindFirstIntersection(
            Parametrisation startingParametersFirstSurface,
            Parametrisation startingParametersSecondSurface
            )
        {
            var currentParametrisation = new IntersectionParametrisation(
                startingParametersFirstSurface,
                startingParametersSecondSurface
                );

            var iterationNumber = 0;

            do
            {
                var nextParametrisation = EvaluateTwoSurfacesNewtonStep(
                    currentParametrisation
                    );

                if (!nextParametrisation.IsValid())
                {
                    return(null);
                }

                if (MinimumStepLength >=
                    IntersectionParametrisation.DistanceNormMax(
                        nextParametrisation,
                        currentParametrisation
                        ))
                {
                    return(nextParametrisation);
                }

                currentParametrisation = nextParametrisation;
            } while (++iterationNumber < MaximumNewtonIterations);

            return(null);
        }
Ejemplo n.º 15
0
        private IntersectionParametrisation EvaluateNextGuessNewtonStep(
            IntersectionParametrisation previousParametrisation,
            Vector previousPoint,
            Vector tangent
            )
        {
            var evaluated = EvaluateIntersectionWithPlaneFunction(
                previousParametrisation,
                previousPoint,
                tangent
                );

            var jacobian = GetJacobianWithPlane(
                previousParametrisation,
                previousPoint,
                tangent
                );

            return(EvaluateNewtonStep(
                       previousParametrisation,
                       jacobian,
                       evaluated
                       ));
        }
Ejemplo n.º 16
0
 public void FindLoopAndIsolate(IntersectionParametrisation value)
 {
 }
Ejemplo n.º 17
0
 public void Add(IntersectionParametrisation parametrisation)
 {
     Polygon.Add(parametrisation);
 }