예제 #1
0
        public Parametrisation FindNearest(
            IParametricSurface surface,
            Point3D referencePoint
            )
        {
            Parametrisation closestParametrisation = new Parametrisation();
            var             closestDistance        = double.MaxValue;

            for (var u = 0; u < SamplesU; ++u)
            {
                for (var v = 0; v < SamplesV; ++v)
                {
                    var paramU   = u / (SamplesU - 1.0);
                    var paramV   = v / (SamplesV - 1.0);
                    var location = surface.Evaluate(paramU, paramV);
                    var distance = (referencePoint - location).Length;
                    if (closestDistance > distance)
                    {
                        closestDistance        = distance;
                        closestParametrisation = new Parametrisation(
                            paramU,
                            paramV
                            );
                    }
                }
            }

            return(closestParametrisation);
        }
        public void Build(IParametricSurface surface)
        {
            _sampledSurface = surface;

            var samplesU =
                GlobalSettings.QualitySettingsViewModel.SurfaceHSubdivisions;
            var samplesV =
                GlobalSettings.QualitySettingsViewModel.SurfaceWSubdivisions;
            var lineSamples = 32;

            Func <int, double> uCoordGenerator = (i) => i / (samplesU - 1.0);
            Func <int, double> vCoordGenerator = (i) => i / (samplesV - 1.0);
            Func <int, double> lineGenerator   = (i) => i / (lineSamples - 1.0);

            for (var i = 0; i < samplesU; ++i)
            {
                var uCoord = uCoordGenerator(i);
                ScanConstantParameter(
                    (unused) => uCoord,
                    lineGenerator,
                    lineSamples
                    );
            }

            for (var i = 0; i < samplesV; ++i)
            {
                var vCoord = vCoordGenerator(i);
                ScanConstantParameter(
                    lineGenerator,
                    (unused) => vCoord,
                    lineSamples
                    );
            }
        }
예제 #3
0
 public static Point3D Evaluate(
     this IParametricSurface surface,
     Parametrisation parametrisation
     )
 {
     return(surface.Evaluate(
                parametrisation.U,
                parametrisation.V
                ));
 }
예제 #4
0
        public PolygonIntersection FindIntersectionPolygon(
            IParametricSurface firstSurface,
            IParametricSurface secondSurface,
            Point3D intersectionNearPoint
            )
        {
            _surfaces[0] = firstSurface;
            _surfaces[1] = secondSurface;

            var firstGuessParametrisation = NearestPointFinder.FindNearest(
                _surfaces[0],
                intersectionNearPoint
                );

            var secondGuessParametrisation = NearestPointFinder.FindNearest(
                _surfaces[1],
                intersectionNearPoint
                );

            firstGuessParametrisation.Boundaries =
                firstSurface.ParametrisationBoundaries;
            secondGuessParametrisation.Boundaries =
                secondSurface.ParametrisationBoundaries;

            var trackingDistanceSetting = TrackingDistance;

            TrackingDistance = -trackingDistanceSetting;
            var polygonPart = GetDirectionalPolygonPart(
                firstGuessParametrisation,
                secondGuessParametrisation
                );

            if (polygonPart.IsLooped)
            {
                return(polygonPart);
            }

            TrackingDistance = trackingDistanceSetting;
            var polygonRemainingPart = GetDirectionalPolygonPart(
                firstGuessParametrisation,
                secondGuessParametrisation
                );

            if (polygonRemainingPart.IsLooped)
            {
                return(polygonRemainingPart);
            }

            return(PolygonIntersection.JoinFromSamePoint(
                       polygonPart,
                       polygonRemainingPart
                       ));
        }
예제 #5
0
 public static Vector3D Derivative(
     this IParametricSurface surface,
     Parametrisation parametrisation,
     DerivativeParameter parameter
     )
 {
     return(surface.Derivative(
                parametrisation.U,
                parametrisation.V,
                parameter
                ));
 }
예제 #6
0
        public void DrawDerivative(
            IParametricSurface surface,
            double u,
            double v,
            DerivativeParameter parameter,
            Color?color = null
            )
        {
            var point      = surface.Evaluate(u, v);
            var derivative = surface.Derivative(u, v, parameter);

            DrawVector(point, derivative, derivative.Length, color);
        }
예제 #7
0
        public static Vector3D Normal(
            this IParametricSurface surface,
            Parametrisation parametrisation)
        {
            var du = surface.Derivative(
                parametrisation,
                DerivativeParameter.U
                );

            var dv = surface.Derivative(
                parametrisation,
                DerivativeParameter.V
                );

            return(Vector3D.CrossProduct(du, dv));
        }
예제 #8
0
        /// <summary>
        /// Calculates F(u,v) = dot(P(u,v) - P, t) - d
        /// </summary>
        /// <param name="surface"></param>
        /// <param name="parametrisation"></param>
        /// <param name="previousPoint"></param>
        /// <param name="tangentVector"></param>
        /// <returns></returns>
        private DenseVector EvaluatePlaneEquation(
            IParametricSurface surface,
            Parametrisation parametrisation,
            Vector previousPoint,
            Vector tangentVector
            )
        {
            var surfacePosition =
                ((Vector3D)surface.Evaluate(parametrisation)).ToMathVector();

            var position = surfacePosition - previousPoint;
            var dot      = position.DotProduct(tangentVector);
            var tangentZeroEquationValue   = dot - TrackingDistance;
            var tantentPlaneEquationVector = DenseVector.OfArray(new[]
            {
                tangentZeroEquationValue,
                tangentZeroEquationValue,
                tangentZeroEquationValue
            });

            return(tantentPlaneEquationVector);
        }
예제 #9
0
        private DenseVector EvaluateNumericalDerivativeForPlaneEquation(
            IParametricSurface surface,
            Parametrisation parametrisation,
            Vector previousPoint,
            Vector tangentVector,
            DerivativeParameter parameter
            )
        {
            var             parametrisationStep = 0.01;
            Parametrisation newParametrisation;

            switch (parameter)
            {
            case DerivativeParameter.U:
                if (parametrisation.U > 1 - parametrisationStep - 0.001)
                {
                    parametrisationStep = -parametrisationStep;
                }

                newParametrisation = parametrisation + new Parametrisation(
                    parametrisationStep,
                    0.0
                    );

                break;

            case DerivativeParameter.V:
                if (parametrisation.V > 1 - parametrisationStep - 0.001)
                {
                    parametrisationStep = -parametrisationStep;
                }

                newParametrisation = parametrisation + new Parametrisation(
                    0.0,
                    parametrisationStep
                    );

                break;

            default:
                throw new ArgumentOutOfRangeException(
                          nameof(parameter),
                          parameter,
                          null
                          );
            }

            var currentValues = EvaluatePlaneEquation(
                surface,
                parametrisation,
                previousPoint,
                tangentVector
                );

            var shiftedValues = EvaluatePlaneEquation(
                surface,
                newParametrisation,
                previousPoint,
                tangentVector
                );

            return((shiftedValues - currentValues) / parametrisationStep);
        }