예제 #1
0
 private Vector3D EvaluateIntersectionFunction(
     IntersectionParametrisation parametrisation
     )
 {
     return(_surfaces[0].Evaluate(parametrisation.First) -
            _surfaces[1].Evaluate(parametrisation.Second));
 }
예제 #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 },
            }));
        }
예제 #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);
        }
예제 #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);
        }
예제 #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)
                ));
 }
예제 #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);
        }
예제 #8
0
        private static IntersectionParametrisation EvaluateNewtonStep(
            IntersectionParametrisation previousParametrisation,
            Matrix jacobian,
            Vector evaluatedFunction
            )
        {
            var jacobianInv = GetPseudoInverse(jacobian);
            var correction  = jacobianInv * evaluatedFunction;

            return(previousParametrisation - correction);
        }
예제 #9
0
        private Matrix GetJacobianWithPlane(
            IntersectionParametrisation previousParametrisation,
            Vector previousPoint,
            Vector tangentVector
            )
        {
            var simpleJacobian = GetJacobian(previousParametrisation);
            var planeJacobian  = GetPlaneJacobian(
                previousParametrisation,
                previousPoint,
                tangentVector
                );

            return(simpleJacobian - planeJacobian);
        }
예제 #10
0
        private IntersectionParametrisation EvaluateTwoSurfacesNewtonStep(
            IntersectionParametrisation previousParametrisation
            )
        {
            var evaluatedFunction =
                EvaluateIntersectionFunction(previousParametrisation)
                .ToMathVector();

            var jacobian = GetJacobian(previousParametrisation);

            return(EvaluateNewtonStep(
                       previousParametrisation,
                       jacobian,
                       evaluatedFunction
                       ));
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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
                       ));
        }
예제 #16
0
 public void FindLoopAndIsolate(IntersectionParametrisation value)
 {
 }
예제 #17
0
 public void Add(IntersectionParametrisation parametrisation)
 {
     Polygon.Add(parametrisation);
 }