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); }
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); }
public static void DrawLine( WriteableBitmap writeableBitmap, int previewSize, int offset, Parametrisation begin, Parametrisation end ) { var x0 = (int)(begin.U * previewSize); var y0 = (int)(begin.V * previewSize); var x1 = (int)(end.U * previewSize); var y1 = (int)(end.V * previewSize); var maxDistance = (int)(0.8 * previewSize); if (Math.Abs(x0 - x1) > maxDistance || Math.Abs(y0 - y1) > maxDistance) { return; } writeableBitmap.DrawLine( offset + x0, offset + y0, offset + x1, offset + y1, Colors.Red ); }
public IntersectionParametrisation( Parametrisation first, Parametrisation second ) { First = first; Second = second; }
public static double DistanceNormMax( IntersectionParametrisation left, IntersectionParametrisation right ) { return(Math.Max( Parametrisation.DistanceNormMax(left.First, right.First), Parametrisation.DistanceNormMax(left.Second, right.Second) )); }
public IntersectionParametrisation(Vector <double> vector) { if (vector.Count != 4) { throw new ArgumentException( "Intersection parametrisation requires exactly 4 parameters" ); } First = new Parametrisation(vector[0], vector[1]); Second = new Parametrisation(vector[2], vector[3]); }
private PolygonIntersection GetDirectionalPolygonPart( Parametrisation firstGuessParametrisation, Parametrisation secondGuessParametrisation ) { IntersectionParametrisation?previousParametrisation = null; var currentIntersectionParametrisation = FindFirstIntersection( firstGuessParametrisation, secondGuessParametrisation ); var polygon = new PolygonIntersection(); polygon.EqualityEpsilon = 0.001; while (currentIntersectionParametrisation.HasValue && !AreEdgeTrackingBoundaryConditionsFullfilled( previousParametrisation, currentIntersectionParametrisation ) ) { if (polygon.FinishIfLoopedBack( currentIntersectionParametrisation.Value )) { break; } polygon.Add(currentIntersectionParametrisation.Value); var nextGuess = GetNextInitialGuess( currentIntersectionParametrisation.Value ); if (!nextGuess.HasValue) { break; } previousParametrisation = currentIntersectionParametrisation; currentIntersectionParametrisation = FindFirstIntersection( nextGuess.Value.First, nextGuess.Value.Second ); } return(polygon); }
/// <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); }
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); }
public Point3D Evaluate(Parametrisation parametrisation) { return(Evaluate(parametrisation.U, parametrisation.V)); }
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); }