Skip to content

[Core] Fix projection direction in NewtonRaphsonCurve to improve robustness#13564

Merged
juancamarotti merged 6 commits intomasterfrom
core/brep_curve_projection_correction
Jun 27, 2025
Merged

[Core] Fix projection direction in NewtonRaphsonCurve to improve robustness#13564
juancamarotti merged 6 commits intomasterfrom
core/brep_curve_projection_correction

Conversation

@juancamarotti
Copy link
Contributor

🔧 Fix: Improve Direction Handling in NewtonRaphsonCurve Projection

✨ What’s new
This PR enhances the robustness of the NewtonRaphsonCurve function in ProjectionNurbsGeometryUtilities by correcting the direction of the parametric update using geometric information.

🧠 Why
When projecting points far from the curve or close to the curve extremes, the Newton-Raphson update can mistakenly move in the wrong direction along the curve due to poor alignment with the tangent. This may lead to:

  • Divergence or overshooting,

  • Fallback to endpoints,

  • Incorrect projections.

📐 How it works
We compute the global-space update vector:

update_vector = delta_t * tangent;

Then compare it with the distance vector:

alignment = inner_prod(update_vector, distance_vector);

If alignment > 0.0, we reverse delta_t to ensure the update moves toward the projection target.

@rickyaristio
Copy link
Contributor

rickyaristio commented Jun 25, 2025

We need a test for this, especially a case when the existing implementation fails.

@juancamarotti
Copy link
Contributor Author

We need a test for this, especially a case when the existing implementation fails.

Done @rickyaristio

@juancamarotti
Copy link
Contributor Author

It's ready @rickyaristio, could you check it ?

rickyaristio
rickyaristio previously approved these changes Jun 26, 2025
@juancamarotti
Copy link
Contributor Author

juancamarotti commented Jun 26, 2025

@sunethwarna could you take a look at this PR? Thanks

sunethwarna
sunethwarna previously approved these changes Jun 27, 2025
Copy link
Member

@sunethwarna sunethwarna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @juancamarotti .... I checked the technical stuff, I'll leave the algorithmic and formulation stuff approval to @rickyaristio.


KRATOS_EXPECT_NEAR(parameter_extreme[0], -1.0, TOLERANCE);

std::vector<double> projected_point_extreme1 = {-9.0, -2.0, 0.0};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why std::vector in here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed :)

Co-authored-by: Suneth Warnakulasuriya <7856520+sunethwarna@users.noreply.github.com>
@juancamarotti juancamarotti dismissed stale reviews from sunethwarna and rickyaristio via 472c521 June 27, 2025 06:59
juancamarotti and others added 2 commits June 27, 2025 08:59
Co-authored-by: Suneth Warnakulasuriya <7856520+sunethwarna@users.noreply.github.com>
@juancamarotti juancamarotti merged commit 5def980 into master Jun 27, 2025
11 checks passed
@juancamarotti juancamarotti deleted the core/brep_curve_projection_correction branch June 27, 2025 09:55
@rickyaristio
Copy link
Contributor

Thanks @juancamarotti .... I checked the technical stuff, I'll leave the algorithmic and formulation stuff approval to @rickyaristio.

no more comments from my side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants